bind
can.Map.prototype.bind
Bind event handlers to an Map.
map.bind(eventType, handler)
Parameters
-
eventType
{String}
the type of event to bind this handler to
-
handler
{function()}
the handler to be called when this type of event fires The signature of the handler depends on the type of event being bound. See below for details.
Returns
{can.Map}
this Map, for chaining
bind
binds event handlers to property changes oncan.Map
s. When you change a property usingattr
, two events are fired on the Map, allowing other parts of your application to map the changes to the object.The change event
The first event that is fired is the change event. The change event is useful if you want to react to all changes on an Map.
The parameters of the event handler for the change event are:
'add'
,'remove'
, or'set'
.newVal
will beundefined
if the property was removed.oldVal
will beundefined
if the property was added.Here is a concrete tour through the change event handler's arguments:
(See also
removeAttr
, which removes properties).The property name event
The second event that is fired is an event whose type is the same as the changed property's name. This event is useful for noticing changes to a specific property.
The parameters of the event handler for the property name event are:
newVal
will beundefined
if the property was removed.oldVal
will beundefined
if the property was added.Here is a concrete tour through the property name event handler's arguments:
See also
More information about changing properties on Observes can be found under attr.
For a more specific way to changes on Observes, see the delegate plugin.