https://github.com/nodejs/node/blob/2f9c9eebb43696bda0467f119951b5914a348994/lib/events.js#L198
Why do you bind ”this“ here?It is not compatible with browser.
Why do you bind ”this“ here?
Mostly because it’s often useful, I assume – it means you don’t have to store the object in another way, and often you can avoid having a closure this way.
It is not compatible with browser.
Node’s EventEmitter API doesn’t match the browser’s EventTarget API in a number of ways – that’s unfortunate, but it’s not something we could reasonably change easily.
I’d say there’s a chance that EventTarget could be introduced into Node as it adopts more and more Browser APIs, but too much code relies on how the current EventEmitter API works for us to make changes to that.
it’s a best way when you extend EventEmitter
just to clarify, events emitted by EventTarget also bind this to the target, so there's not actually any difference here.
Seems like not an issue? Closing...
I’d say there’s a chance that
EventTargetcould be introduced into Node
Would really like to see EventEmitter etc being implemented in node too so that ppl building cross browser/platform works the same way without any additional dependencies
Most helpful comment
Mostly because it’s often useful, I assume – it means you don’t have to store the object in another way, and often you can avoid having a closure this way.
Node’s
EventEmitterAPI doesn’t match the browser’sEventTargetAPI in a number of ways – that’s unfortunate, but it’s not something we could reasonably change easily.I’d say there’s a chance that
EventTargetcould be introduced into Node as it adopts more and more Browser APIs, but too much code relies on how the currentEventEmitterAPI works for us to make changes to that.