Skip to content

Should nextTick and timers accept context or parameters? #953

@benjamingr

Description

@benjamingr

Currently, both timers and nextTick only take a callback argument (and some timers take a duration argument).

It is beneficial to pass additional arguments and/or the context to timers. The io.js code base is littered with code like:

  var self = this;
  process.nextTick(function() {
    self.emit('close');
  });

It's possible to either pass a context (this) to these functions or to pass arguments like the DOM version does making the above:

  process.nextTick(function() {
     this.emit('close');
   }, this);

Or:

  process.nextTick(function(element) {
     element.emit('close');
   }, this);

This can make cleaner code and save closure allocations - it also isn't slow like .bind.

Was this proposed before?

I realize the Timers API is locked (nextTick is not afaict) but I'm wondering how people feel about this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions