智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
LightingSystemApp-serial/.svn/pristine/e4/e42f2ec2425c3d2048e211a00dc...

66 lines
1.7 KiB

var Class = require('./Class');
var has = require('./has');
var each = require('./each');
var slice = require('./slice');
var once = require('./once');
exports = Class(
{
initialize: function Emitter() {
this._events = this._events || {};
},
on: function(event, listener) {
this._events[event] = this._events[event] || [];
this._events[event].push(listener);
return this;
},
off: function(event, listener) {
var events = this._events;
if (!has(events, event)) return;
var idx = events[event].indexOf(listener);
if (idx > -1) {
events[event].splice(idx, 1);
}
return this;
},
once: function(event, listener) {
this.on(event, once(listener));
return this;
},
emit: function(event) {
if (!has(this._events, event)) return;
var args = slice(arguments, 1);
each(
this._events[event],
function(val) {
val.apply(this, args);
},
this
);
return this;
},
removeAllListeners: function(event) {
if (!event) {
this._events = {};
} else {
delete this._events[event];
}
return this;
}
},
{
mixin: function(obj) {
each(['on', 'off', 'once', 'emit'], function(val) {
obj[val] = exports.prototype[val];
});
obj._events = obj._events || {};
}
}
);
module.exports = exports;