Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update on(readable) to not rely on magical this binding #288

Open
Pomax opened this issue Apr 2, 2021 · 0 comments
Open

update on(readable) to not rely on magical this binding #288

Pomax opened this issue Apr 2, 2021 · 0 comments

Comments

@Pomax
Copy link

Pomax commented Apr 2, 2021

This is an API update request.

Currently the README shows the following code:

feedparser.on('readable', function () {
  // This is where the action is!
  var stream = this; // `this` is `feedparser`, which is a stream
  ...
});

However, relying on non-standard ("magic") this binding breaks the declaration model of modern JS (we can't use arrow functions now, for example), not to mention being essentially unnecessary: we can just make it the callback argument:

feedparser.on('readable', function (stream) {
   ...
});

Now we can use modern arrow functions too, without this rebinding breaking things:

feedparser.on('readable', stream => this.handleStream(stream));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant