Giter VIP home page Giter VIP logo

Comments (6)

heapwolf avatar heapwolf commented on June 14, 2024

This is simply an oversight on my part. I'd like it to work more like the native eventemitter, that's the end goal.

from eventemitter2.

heapwolf avatar heapwolf commented on June 14, 2024

Oh, duh. EventEmitter2.call(this); // or w/args, works fine.

from eventemitter2.

jvduf avatar jvduf commented on June 14, 2024

Yea but you can not mix it in like in Node:

util.inherits(Agent, EventEmitter);

So if you want to "inherit" the functions of EventEmitter2 on - let's say - Agent you have to call EventEmitter2 with the scope of Agent in Agent's constructor. If you want to mix in Agent into another object you have to do that same thing on the that other object.

util.inherits in Node.js simply copies the prototype of one object to the other. So the constructor setup like EventEmitter2 uses right now doesn't work correctly because the constructor does not get fired.

from eventemitter2.

heapwolf avatar heapwolf commented on June 14, 2024

The .call or .apply that I pointed out allows for what you're trying to do with sys.inherits

from eventemitter2.

mcasimir avatar mcasimir commented on June 14, 2024

Still not working for me.

var EventEmitter2 = require('eventemitter2').EventEmitter2;

function Backend(endpoint, http, ws) {
  EventEmitter2.call(this);

  this.endpoint = http;
  this.http = http;
  this.ws = ws;
}

module.exports = Backend;
var Backend = require('../../src/backend');
var backend = new Backend();
console.log(typeof backend.on);
// -> undefined

Anyway this is a quite common use case, definitely consider to document it at least.

from eventemitter2.

julianh2o avatar julianh2o commented on June 14, 2024

I ran into this too. I was looking to "upgrade" from EventEmitter to EventEmitter2 because of the onAny support but my code uses util.inherits. It's not a problem to refactor my code, but it caught me by surprise as I was expecting a drop-in replacement.

EDIT: On further investigation, the issues I'm seeing may be completely unrelated..

from eventemitter2.

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.