Skip to content

Instantly share code, notes, and snippets.

@teresko
Created December 3, 2014 00:18
Show Gist options
  • Save teresko/cc291e66fa0ad06aaa0d to your computer and use it in GitHub Desktop.
Save teresko/cc291e66fa0ad06aaa0d to your computer and use it in GitHub Desktop.
var components = components || {};
(function (globals) {
"use strict";
/**
* Event manager
*/
globals.emitter = (function () {
var handlers = {};
return {
/**
* register never event
*/
on: function (name, scope, callback) {
handlers[name] = (handlers[name] || []).concat({
callback: callback,
scope: scope
});
},
/**
* trigger said event
*/
trigger: function (name, parameters) {
(handlers[name] || []).forEach(function (handler) {
handler.callback.call(handler.scope, parameters || []);
});
}
};
}());
}(components));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment