Last active
December 17, 2015 06:38
-
-
Save ziluo/5566599 to your computer and use it in GitHub Desktop.
JS订阅模式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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