标签:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var event={
clientList:[],
listen:function(key,fn){
if(!this.clientList[key]){
this.clientList[key]=[];
}
this.clientList[key].push(fn);
},
trigger:function(){
var key=Array.prototype.shift.call(arguments);
var fns=this.clientList[key];
if(!fns||fns.length===0) {
return false;
}
for(var i=0,fn;fn=fns[i++];){
fn.apply(this,arguments);
}
},
remove:function(key,fn){
var fns=this.clientList[key];
if(!fns){
return false;
}
if(!fn){
fns&&(fns.length=0);
}
else{
for(var i=fns.length-1;i>=0;i--){
var _fn=fns[i];
if(_fn===fn){
fns.splice(i,1);
}
}
}
}
}
event.listen("aa",a=function(price){alert(price)});
event.listen("aa",b=function(price){alert(price)});
event.remove("aa",a);
event.trigger("aa","111");
//event.trigger("aa","111");
var nav=(function(){
var a=1;
return bniu:function(){
alert(a+3);
}
})();
nav.bniu();
</script>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/yaopj/p/5356276.html