function Emitter() {
}
Emitter.prototype = function() {
var events = {};
return {
constructor: Emitter,
on: function(type, cb) {
var arr = events[type] = events[type] || [];
(arr.indexOf(cb) === -1) && arr.push(cb);
return this;
},
off: function(type, cb) {
var arr = events[type] = events[type] || [], i = 0;
while(arr.length !== i) {
if (arr[i] === cb) {
arr.splice(i, 1);
break;
}
i++;
}
return this;
},
emitter: function(type) {
var arr = events[type] = events[type] || [], i = 0;
while(arr.length !== i) {
arr[i].apply(this, [].slice.call(arguments, 1));
i++;
}
return this;
}
}
}();
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。