Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
在nodejs的官方文档中,明确写出了node的一个特性是event-driven(事件驱动),可见其非常重要。查看源码,我们可知其事件机制为用js写的EventEmitter类,写得非常优雅且应用了发布/订阅模式。
通过实现一个简易的、具有发布/订阅模式的事件机制,以此来理清EventEmitter类的实现思路
Publish/Subscribe(发布/订阅模式)
类比
要讲的是一个模式,模式这个词,听起