1

Could someone please confirm if these two methods are effectively the same

process.nextTick(callback.bind(undefined, results));

Vs.

process.nextTick(function() {
   callback(results));
});

And if they successfully make the callbacks asynchronous from a node js perspective.

1

1 Answer 1

1

They might be the same, yes.

There's one minor difference though: The time at which results is evaluated. When you use bind, it takes the value immediately, when you use the callback the value is determined at the time of the actual call.

Example where they're different:

var results = 1;
process.nextTick(console.log.bind(console, results));
process.nextTick(function() { console.log(results)); });
results = 2;

// will log "1" and "2"
Sign up to request clarification or add additional context in comments.

1 Comment

That's actually quite interesting, I wasn't aware.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.