Last active
December 10, 2015 04:38
-
-
Save kulte/4382606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A module that can be mixed in to *any object* in order to provide it with | |
// custom events. You may bind with `on` or remove with `off` callback | |
// functions to an event; `trigger`-ing an event fires all callbacks in | |
// succession. | |
// | |
// var object = {}; | |
// _.extend(object, Backbone.Events); | |
// object.on('expand', function(){ alert('expanded'); }); | |
// object.trigger('expand'); | |
// | |
var Events = Backbone.Events = { | |
// Bind one or more space separated events, or an events map, | |
// to a `callback` function. Passing `"all"` will bind the callback to | |
// all events fired. | |
on: function(name, callback, context) { | |
if (!(eventsApi(this, 'on', name, [callback, context]) && callback)) return this; | |
this._events || (this._events = {}); | |
var list = this._events[name] || (this._events[name] = []); | |
list.push({callback: callback, context: context, ctx: context || this}); | |
return this; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment