Giter Site home page Giter Site logo

Comments (8)

defunctzombie avatar defunctzombie commented on July 19, 2024

Can we get a fix and test PR for this?
On May 30, 2014 6:57 PM, "lpstein" [email protected] wrote:

Behavior broke in node 0.10, see nodejs/node-v0.x-archive#7157
nodejs/node-v0.x-archive#7157 fixed in node.js master
vkurchatkin/node@2956f03
.

Example:

var A = function() {};A.prototype = new events.EventEmitter();
var a1 = new A();var a2 = new A();
a1.on('test', function() {
console.log('test');});a2.emit('test');

This logs 'test' where it shouldn't.


Reply to this email directly or view it on GitHub
#10.

from events.

defunctzombie avatar defunctzombie commented on July 19, 2024

The fix from node.js master doesn't work in ie8. So if we want to keep parity with current browsers we support the fix has to be different. Personally don't care about dropping IE8 support.

from events.

darkyen avatar darkyen commented on July 19, 2024

Drop IE 8 ? Please ?

from events.

leewaygroups avatar leewaygroups commented on July 19, 2024

@lpstein Looking at your code example, a2.emit('test'); , logging 'test' is normal.

Reason
A.prototype = new events.EventEmitter(); implies that every instance of A will share among other things same copy of events collection -- Pure case of prototypal inheritance.

Suppose you do not want this, you can make instances have their own private events collection by:
var A = function() {
events.EventEmitter.call(this);
};

Note: this does not take away the shared events collection as explained earlier, it only shadows it.

Another option is to require util module then do this:
util.inherits(A, events.EventEmitter);

Cheers!!

from events.

patrickroberts avatar patrickroberts commented on July 19, 2024

You can also do something like:

function A() {
  events.EventEmitter.call(this);
}

A.prototype = Object.create(events.EventEmitter.prototype);
A.prototype.constructor = A;

That's one of the methods Babel uses to transpile ES6 inheritance when Object.setPrototypeOf doesn't exist. And it doesn't just shadow it, it doesn't even create a shared events collection since Object.create() does not invoke the constructor!

from events.

lpstein avatar lpstein commented on July 19, 2024

This is an automatically generated message.

[email protected] is no longer with Yahoo! Inc.

Your message will not be forwarded.

If you have a sales inquiry, please email [email protected] and someone will follow up with you shortly.

If you require assistance with a legal matter, please send a message to [email protected]

Thank you!

from events.

darkyen avatar darkyen commented on July 19, 2024

Yahoooo spam!

from events.

goto-bus-stop avatar goto-bus-stop commented on July 19, 2024

Fixed in #40. Will try to release soon once I get it working on IE8 again

from events.

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.