silverwind
silverwind

Reputation: 3934

callbacks: function vs. function.bind

Is there a difference between supplying a callback method with and without bind when I don't want to modify arguments? For example, is

async(console.log)

and

async(console.log.bind(console))

technically equivalent or are there cases with different behaviour?

Upvotes: 0

Views: 64

Answers (1)

jcubic
jcubic

Reputation: 66660

You need to use bind if you want to pass function that need proper context like console.log otherwise you can just pass a function. Try to run log as this:

var log = console.log;
log('x');

You will get exception because log need to called with console as context.

Upvotes: 1

Related Questions