js 观察者模式demo | 前端大队长

js 观察者模式demo

var fabuobj = function(){
this.dingyue = {}
}
fabuobj.prototype = {
constructor: fabuobj,
todingyue :function(ren,ev){
if(ren in this.dingyue){
alert('yi ding')
return
}
this.dingyue[ren] = ev;
console.log(this.dingyue,2222)
},
nodingyue : function(){},
tofabu :function(ren,ev){
if(!this.dingyue[ren]){
return
}
this.dingyue[ren](ev)
}
}
var a = new fabuobj()

a.todingyue('a',function(res){
console.log(res)
})
a.tofabu('a','1aaawwwww')

 

 

凑合看

Latest posts by admin (see all)