-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevented.js
More file actions
26 lines (25 loc) · 796 Bytes
/
evented.js
File metadata and controls
26 lines (25 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var Evented = {
Event: {
on: function(event, callback, context) {
this.hasOwnProperty('events') || (this.events = {});
this.events.hasOwnProperty(event) || (this.events[event] = []);
this.events[event].push([callback, context]);
},
trigger: function(event) {
var tail = Array.prototype.slice.call(arguments, 1),
callbacks = this.events[event];
for(var i = 0, l = callbacks.length; i < l; i++) {
var callback = callbacks[i][0],
context = callbacks[i][1] === undefined ? this : callbacks[i][1];
callback.apply(context, tail);
}
}
},
extend: function(other) {
for (var property in this.Event) {
other[property] = this.Event[property];
}
return other;
}
};
exports.Evented = Evented;