i was looking on the jQuery source code and then i saw that they use foo.call(context) instead of context.foo().
for example- assuming this is array they use:
return slice.call( this );
instead of:
return this.slice();
what is the difference and is it the prefer way (in terms of performance) doing those calls?
The problem is that “foo” might not actually be a property of “context”. When that’s the case, the only real choice is to use
.call()(or.apply(), as appropriate).If you do have an object with a “foo” property that’s a function, then there’s no real reason to use
.call().