can.event
2.1
can.event
Add event functionality into your objects.
The can.event
object provides a number of methods for handling events in objects. This functionality is best used by mixing the can.event
object into an object or prototype. However, event listeners can still be used even on objects that don't include can.event
.
All methods provided by can.event
assume that they are mixed into an object -- this
should be the object dispatching the events.
can.extend(YourClass.prototype, can.event)
Adds event functionality to YourClass
objects. This can also be applied to normal objects: can.extend(someObject, can.event)
.
Using as a mixin
The easiest way to add events to your classes and objects is by mixing
can.event
into your object or prototype.Now that
can.event
is included in the prototype, we can add/remove/dispatch events on the object instances.Using without mixing in
The same event functionality from
can.event
can be used, even if the given object doesn't includecan.event
. Every method withincan.event
supports being called with an alternate scope.