Guys I would like a theoretical answer for this question.
I would like to know if calling f.call(null,x) is any possibly slower than calling f(x) ?
As this test shows, executing the function directly, wins.
function foo(x) {
for (var i = 0; i < 100; i++);
}
// Tests
foo('Bob');
foo.call(null, 'Fish');
foo.call(window, 'Cowboy!');
Yes, it will be very marginally slower because of the addition property lookup (finding member call on function f). It is very much a micro-optimization and not something that should put you off using call() when it's necessary.
On the other hand, I've noticed that functions created with bind() are slower than their unbound counterparts and also slower than using call(), in most browsers. Just in case you were thinking that may be a way around any performance deficit.
Note that someone has already set up some tests for this over at http://jsperf.com.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With