Event Emitter
Tips:
- 先注册listener - on,后emit
- Listener function 同步执行
- 'on' is an alias of 'addListener'
- 'of' is an alias of 'removeListener'
- 常用:
- on\off\emit\once
- eventNames
- prependListener: 在array前面加listener = unshift
- rawListeners: 所有listener的function(包括once)
- max: 同event name上的listener>10个时,需要specific设置
- node inherit modules:stream.on(‘data’,()=>{}) \ process.on(‘exit’,()=>{})
实现:
https://www.freecodecamp.org/news/how-to-code-your-own-event-emitter-in-node-js-a-step-by-step-guide-e13b7e7908e1/
本文标题:Event Emitter
本文链接:https://www.haomeiwen.com/subject/qnrxyhtx.html
网友评论