Function.bind vs Closure in Javascript : how to choose?

Viewed 13238

As said here:

http://jqfundamentals.com/book/index.html

Closures can also be used to resolve issues with the this keyword, which is unique to each scope. This mechanism can be particularly useful when dealing with callbacks, though in those cases, it is often better to use Function.bind, which will avoid any overhead associated with scope traversal.

But it doesn't really say how to distinguish between the two cases. I don't understand in fact what the author means by "avoid any overhead associated with scope traversal." Can you explain?

3 Answers

jsperf is dead. meet perf.link.

i'm seeing a different victor each time i run the benchmark. my guess is, modern browsers optimize away most of the disadvantages of either of these approaches.

Related