1/** 2 * MicroEvent - to make any js object an event emitter (server or browser) 3 * 4 * - pure javascript - server compatible, browser compatible 5 * - dont rely on the browser doms 6 * - super simple - you get it immediatly, no mistery, no magic involved 7 * 8 * - create a MicroEventDebug with goodies to debug 9 * - make it safer to use 10*/ 11 12var MicroEvent = function(){}; 13MicroEvent.prototype = { 14 bind : function(event, fct){ 15 this._events = this._events || {}; 16 this._events[event] = this._events[event] || []; 17 this._events[event].push(fct); 18 }, 19 unbind : function(event, fct){ 20 this._events = this._events || {}; 21 if( event in this._events === false ) return; 22 this._events[event].splice(this._events[event].indexOf(fct), 1); 23 }, 24 trigger : function(event /* , args... */){ 25 this._events = this._events || {}; 26 if( event in this._events === false ) return; 27 for(var i = 0; i < this._events[event].length; i++){ 28 this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1)); 29 } 30 } 31}; 32 33/** 34 * mixin will delegate all MicroEvent.js function in the destination object 35 * 36 * - require('MicroEvent').mixin(Foobar) will make Foobar able to use MicroEvent 37 * 38 * @param {Object} the object which will support MicroEvent 39*/ 40MicroEvent.mixin = function(destObject){ 41 var props = ['bind', 'unbind', 'trigger']; 42 for(var i = 0; i < props.length; i ++){ 43 if( typeof destObject === 'function' ){ 44 destObject.prototype[props[i]] = MicroEvent.prototype[props[i]]; 45 }else{ 46 destObject[props[i]] = MicroEvent.prototype[props[i]]; 47 } 48 } 49 return destObject; 50} 51 52// export in common js 53if( typeof module !== "undefined" && ('exports' in module)){ 54 module.exports = MicroEvent; 55}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.