//发布订阅模式(NodeJs版)
let eventEmiter = {
on(event, fun) {
this[event]=fun
},
emit(event,...arg){
this[event](...arg)
}
}
eventEmiter.on("build", function (name,lang) {
console.log(name+"正在写"+lang)
})
eventEmiter.emit("build", "张三","Java")
原文:https://www.cnblogs.com/botaoJava/p/14720398.html