Comments (6)
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.
Oh, duh. EventEmitter2.call(this); // or w/args, works fine.
from eventemitter2.
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.
The .call or .apply that I pointed out allows for what you're trying to do with sys.inherits
from eventemitter2.
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.
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)
- proposal: rewrite source in typescript HOT 5
- Wildcard listener not invoked when also matching exact listener HOT 5
- a typo in `toObject` HOT 1
- Make it more ESM module friendly HOT 4
- addListener types definition missing options parameter HOT 1
- Why not Promise.allSettled instead of Promise.all?
- Graceful Shutdown HOT 1
- Feature Request: await emitter.onAny() HOT 1
- Export interface WaitForFilter HOT 1
- An index signature parameter type must be either 'string', 'symbol' or 'number' HOT 10
- [QUESTION]How to on many eventNames when wildcard is true
- logPossibleMemoryLeak throws an error when event name is a Symbol
- EventEmitter2 is not handling throw exception and closing app HOT 4
- [request] Add method to add an EventEmitter to class that already extends another class
- How to obtain eventemitter2.min.js
- EventEmitter in JavaScript can cause out of memory
- Not compatible with strict CSP due to `new Function(..)`
- Is there a way of configuring anctions to be ran before and after the handle of an event?
- Listener execution order regarding wildcards HOT 1
- offAny typings must support no arguments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eventemitter2.