can-define
Version:
Create observable objects with JS dot operator compatibility
48 lines (33 loc) • 1.97 kB
Markdown
can-define/map/map.prototype.set set
can-define/map/map.prototype
Sets multiple properties on a map instance or a property that wasn't predefined.
`map.set(propName, value)`
Assigns _value_ to a property on this map instance called _propName_. This will define
the property if it hasn't already been predefined.
```js
import {DefineMap} from "can";
const map = new DefineMap({});
map.set("propA", "value");
console.log( map.serialize() ); //-> {propA: "value"}
```
Predefined properties can always set the property directly: `map.propName = value`.
{String} propName The property to set.
{*} value The value to assign to `propName`.
{can-define/map/map} This map instance, for chaining.
`map.set(props [,removeProps])`
Assigns each value in `props` to a property on this map instance named after the
corresponding key in `props`, effectively merging `props` into the Map. If `removeProps` is true, properties not in
`props` will be set to `undefined`.
<section class="warnings">
<div class="deprecated warning">
<h3>Deprecated 3.10.1</h3>
<div class="signature-wrapper">
<p>Passing an {Object} to <code>.set</code> has been deprecated in favor of <a href="map.prototype.assign.html" title="Sets multiple properties on a map instance or a property that wasn't predefined.">assign</a> or <a href="map.prototype.update.html" title="Sets multiple properties on a map instance or a property that wasn't predefined.">update</a>. <code>map.set(propName, value)</code> is <em>not</em> deprecated.</p>
</div>
</div>
</section>
{Object} props A collection of key-value pairs to set.
If any properties already exist on the map, they will be overwritten.
{Boolean} [removeProps=false] Whether to set keys not present in `props` to `undefined`.
{can-define/map/map} The map instance for chaining.