can-define
Version:
Create observable objects with JS dot operator compatibility
42 lines (28 loc) • 1.61 kB
Markdown
Returns a plain JavaScript object that contains the properties and values of the map instance. Any property values
that also have a `get` method will have their `get` method called and the resulting value will be used as
the property value. This can be used to recursively convert a map instance to an object of other plain
JavaScript objects. Cycles are supported and only create one object.
`.get()` can still return other non plain JS objects like Date.
Use [can-define/map/map.prototype.serialize] when a form proper for `JSON.stringify` is needed.
```js
import {DefineMap} from "can";
const map = new DefineMap({foo: new DefineMap({bar: "zed"})});
console.log( map.get() ); //-> {foo: {bar: "zed"}};
```
Get a single property on a DefineMap instance.
```js
import {DefineMap} from "can";
const map = new DefineMap();
console.log( map.get("name") ); //-> undefined;
```
`.get(propName)` only needs to be used when reading properties that might not have been defined yet, but will be later via [can-define/map/map.prototype.set]. Predefined properties can always be read like `map.propName`.