attr
can.Map.prototype.attr
Get or set properties on an Map.
map.attr()
Gets a collection of all the properties in this can.Map
.
Returns
{Object<String,*>}
an object with all the properties in this can.Map
.
map.attr(key)
Reads a property from this can.Map
.
Parameters
-
key
{String}
the property to read
Returns
{*}
the value assigned to key.
map.attr(key, value)
Assigns value to a property on this can.Map
called key.
Parameters
-
key
{String}
the property to set
-
the
{*}
value to assign to key.
Returns
{can.Map}
this Map, for chaining
map.attr(obj[, removeOthers])
Assigns each value in obj to a property on this can.Map
named after the
corresponding key in obj, effectively merging obj into the Map.
Parameters
-
obj
{Object<String,*>}
a collection of key-value pairs to set. If any properties already exist on the
can.Map
, they will be overwritten. -
removeOthers
=false
{bool}
Optionalwhether to remove keys not present in obj. To remove keys without setting other keys, use
removeAttr
.
Returns
{can.Map}
this Map, for chaining
attr
gets or sets properties on thecan.Map
it's called on. Here's a tour through how all of its forms work:Deep properties
attr
can also set and read deep properties. All you have to do is specify the property name as you normally would if you weren't usingattr
.Objects that are added to Observes become Observes themselves behind the scenes, so changes to deep properties fire events at each level, and you can bind at any level. As this example shows, all the same events are fired no matter what level you call
attr
at:See also
For information on the events that are fired on property changes and how to listen for those events, see bind.