Skip to content

Instantly share code, notes, and snippets.

@ziluo
Last active December 17, 2015 06:38
Show Gist options
  • Save ziluo/5566599 to your computer and use it in GitHub Desktop.
Save ziluo/5566599 to your computer and use it in GitHub Desktop.
JS订阅模式
var EVENT = (function(){
var bind = function(b){
var queue = this.__MSG_QS__;
if(!queue[b]){
queue[b] = [];
}
for(var a = 1, len = arguments.length, Y; a < len; a++) {
queue[b].push(arguments[a])
}
};
var trigger = function(Y){
var queue = this.__MSG_QS__[Y.type];
if(queue == null){
return;
}
for(var a = 0, len = queue.length; a < len; a++) {
queue[a].handler(Y)
}
};
return {
init: function(X){
X.__MSG_QS__ = {};
X.bind = bind;
X.trigger = trigger;
return X;
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment