Js 基于原型的自定义事件 (20160422)
接手了一个集成项目。界面集成,因为一些原因需要自己去定义事件。不多解释,上代码。。。
var Event={
onFrameworkLoaded:new ProtoEvent("onFrameworkLoaded"),
onGetConnection:new ProtoEvent("onGetConnection")
}
function ProtoEvent(name){
this.name=name;
this.callBacks=[];
}
ProtoEvent.prototype.add=function(callback){
this.callBacks.push(callback);
}
ProtoEvent.prototype.touch=function(value){
for(var call in this.callBacks){
if(this.callBacks[call])this.callBacks[call](value);
}
}
采用的原型的方式来添加

浙公网安备 33010602011771号