1 Star 0 Fork 0

八卦/blog

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
signal.js 862 Bytes
Copy Edit Raw Blame History
i8gua authored 2018-01-09 19:07 +08:00 . release
function _Signal(){
var list = this.list = [], one=[];
/**
* On: listen to list
*/
this.one = function(func){
var self = this;
this.bind(func);
one.push(func);
}
this.bind = function(func){
var i = list.length;
while(i--){
if(func == list[i])return;
}
list.push(func)
}
/**
* Off: stop listening to event / specific callback
*/
this.unbind = function(func){
if(!func){
list = []
return
}
var i = list.length;
while(i--) func == list[i] && list.splice(i,1)
}
/**
* Emit: send event, callbacks will be triggered
*/
this.send = function(){
var i = 0, j;
while(j=list[i++]) j.apply(this,arguments)
i = one.length;
while(i--){
this.unbind(one[i])
}
one = []
};
};
window.Signal = function (){
return new _Signal()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/u8gua/blog.git
git@gitee.com:u8gua/blog.git
u8gua
blog
blog
580871aff3598f44a8539625dd50aa6fcd60d7a3

Search