//订阅者模式
//订阅队列
var lovers = []
let b ={
name:'mary',
}
b.__proto__.yell = function(){
console.log('my name is '+b.name)
}
b.__proto__.namechange = function(subs){
console.log(subs,'my name has changed to '+b.name)
}
//增加新订阅者
b.__proto__.addlover = function(lover){
lovers.push(lover)
}
//广播
b.__proto__.notify = function(subscribers){
subscribers.forEach(function(item,index){
b.namechange(item.name)
})
}
//更新通知订阅者
b.__proto__.changename = function(name){
b.name = name
b.notify(lovers)
}
let roc ={
name:'roc'
}
let sam ={
name:'sam'
}
b.addlover(roc)
b.addlover(sam)
b.changename('susan')
console