Skip to content

Why do you bind ”this“ in event handler #26711

Description

@canfeit

Reflect.apply(handler, this, args);

Why do you bind ”this“ here?It is not compatible with browser.

Activity

  1. added
    eventsIssues and PRs related to EventEmitter and the events module.
    on Mar 17, 2019
  2. addaleax commented on Mar 17, 2019

    @addaleax
    Member

    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.

  3. himself65 commented on Mar 18, 2019

    @himself65
    Member

    it’s a best way when you extend EventEmitter

  4. devsnek commented on Mar 18, 2019

    @devsnek
    Member

    just to clarify, events emitted by EventTarget also bind this to the target, so there's not actually any difference here.

  5. Fishrock123 commented on Mar 18, 2019

    @Fishrock123
    Contributor

    Seems like not an issue? Closing...

  6. jimmywarting commented on Apr 4, 2019

    @jimmywarting

    I’d say there’s a chance that EventTarget could 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    eventsIssues and PRs related to EventEmitter and the events module.questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions