Skip to content

Instantly share code, notes, and snippets.

@vestige
Created May 12, 2011 13:05
Show Gist options
  • Save vestige/968449 to your computer and use it in GitHub Desktop.
Save vestige/968449 to your computer and use it in GitHub Desktop.
oparts.js
var eventualiy = function (that) {
var registry = {};
that.fire = function (event) {
var array,
func,
handler,
i,
type = typeof event === 'string' ? event : event.type;
if (registry.hasOwnProperty(type)) {
array = registry[type];
for (i = 0; i < array.length; i += 1) {
handler = array[i];
func = handler.method;
if (typeof func === 'string') {
func = this[func];
}
func.apply(this, handler.parameters || [event]);
}
}
return this;
};
that.on = function(type, method, parameters) {
var handler = {
method: method,
parameters: parameters
};
if (registry.hasOwnProperty(type)) {
registry[type].push(handler);
} else {
registry[type] = [handler];
}
return this;
};
return that;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment