can-define
Version:
Create observable objects with JS dot operator compatibility
38 lines (26 loc) • 1.16 kB
Markdown
@function can-define/map/map.prototype.assign assign
@parent can-define/map/map.prototype
@description Sets multiple properties on a map instance or a property that wasn't predefined.
@signature `map.assign(props)`
Each value in `props` will be assigned to a property on this map instance named after the
corresponding key in `props`, effectively replacing `props` into the Map. Properties not in `props` will not be changed. For example:
```js
import {DefineMap, DefineList} from "can";
const MyMap = DefineMap.extend({
list: DefineList,
name: "string"
});
const obj = new MyMap({
list: ["1", "2", "3"],
foo: "bar"
});
obj.assign({
list: ["first"]
});
console.log( obj.serialize() ); //-> { foo: "bar", list: ["first"] }
```
@codepen
> **Note:** `.assign` will not remove or change properties that are not in `props`. Use [can-define/map/map.prototype.update .update()] to replace all of a map’s values.
@param {Object} props A collection of key-value pairs to set.
If any properties already exist on the map, they will be overwritten.
@return {can-define/map/map} The map instance for chaining.