世界上最伟大的投资就是投资自己的教育
-
const EventEmitter = require('events');
class Person extends EventEmitter {
constructor(name) {
super();
this.name = name;
}
}let xiaoming = new Person('xiaoming');
let lili = new Person('lili');
let lucy = new Person('lucy');let person = [xiaoming, lili, lucy];
person.forEach(function(person) {
person.on('speak', function(message) {
console.log(person.name + "say" + message);
})
});xiaoming.emit('speak', 'hi');
© 汕尾市求知科技有限公司 | Rails365 Gitlab | Qiuzhi99 Gitlab | 知乎 | b 站 | 搜索
粤公网安备 44152102000088号 | 粤ICP备19038915号
Top