js 之 消息队列
function show(a){
alert(a)
}
callbacks = $.Callbacks();
callbacks.add(function(){
show('a')
})
callbacks.add(function(){
show('b')
})
callbacks.fire() //a,b 注:fire 可跟参数 callbacks.fire('aaaa')
callbacks.remove();//删除
#js实现消息列队
observal = {
callback: [],
add: function(fn){
this.callback.push(fn)
},
fire: function(){
this.callback.forEach(function(a){
a()
})
}
}