assign
Sets multiple properties on a map instance or a property that wasn't predefined.
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:
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"] }
Note:
.assign
will not remove or change properties that are not inprops
. Use .update() to replace all of a map’s values.
Parameters
- props
{Object}
:A collection of key-value pairs to set. If any properties already exist on the map, they will be overwritten.