Code Monkey home page Code Monkey logo

Comments (4)

zhaofeihao avatar zhaofeihao commented on July 30, 2024

它定义了对象间的一种一对多的关系,让多个观察者对象同时监听某一个主题对象,当一个对象发生改变时,所有依赖于它的对象都将得到通知。

对观察者模式这一说法存疑,我的理解 EventEmitter 一边负责注册事件监听,一边负责触发事件,并没有监听到对象发生改变从而使得所有依赖它的对象得到通知,我理解有误吗

from blog.

forthealllight avatar forthealllight commented on July 30, 2024

它定义了对象间的一种一对多的关系,让多个观察者对象同时监听某一个主题对象,当一个对象发生改变时,所有依赖于它的对象都将得到通知。

对观察者模式这一说法存疑,我的理解 EventEmitter 一边负责注册事件监听,一边负责触发事件,并没有监听到对象发生改变从而使得所有依赖它的对象得到通知,我理解有误吗

那你要看看其他监听者对象是不是监听的同一个被监听对象实例。

from blog.

TAUnionOtto avatar TAUnionOtto commented on July 30, 2024

对观察者模式这一说法存疑,我的理解 EventEmitter 一边负责注册事件监听,一边负责触发事件,并没有监听到对象发生改变从而使得所有依赖它的对象得到通知,我理解有误吗

当你使用 eventEmiter.emit(‘foo’) 的时候,发生变化的并不应该是 handles.foo 也不是 eventEmiter,而是你调用 eventEmiter.emit(‘foo’) 的“原因”发生了变化。

比如 readerStream.on('data'),发生变化的不是 heandles.data 也不是 readerStream,而是真正的字节数据 readerStream._someBuffer

EventEmitter 并不关心谁发生了变化,他只负责注册和传递这些变化,但你不能否认 EventEmitter 为实现观察者模式而服务的。

from blog.

cuiliangl avatar cuiliangl commented on July 30, 2024

不算是观察者模式吧。这就是一个订阅发布模式吧

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.