Subpub 订阅/发布

    var Pubsub = (function (window) {
window.handlers = {};
var o = {
pub: function () {
var args = Array.prototype.slice.call(arguments,0),
event = args.shift(); var cbs = handlers[event];
if (cbs) {
for (var i = 0; i < cbs.length; i++) {
cbs[i].apply(cbs[i].args);
}
}
},
sub: function (event, callback) {
if (!handlers[event]) {
handlers[event] = [];
}
handlers[event].push(callback);
}
};
o.publish = o.pub;
o.subscribe = o.sub; return o; })(window); Pubsub.sub("click", function () {
console.log('1 click');
})
Pubsub.sub("click", function () {
console.log('2 click');
})
上一篇:sqlserver 数据库里面金额类型为什么不建议用float,实例告诉你为什么不能。


下一篇:sql*loader以及oracle外部表加载Date类型列