Skip to content

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

Open
@Pomax

Description

@Pomax

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions