+ 4

What is the difference between .call() and .apply()?

They seem to be very similar. What is difference between these two methods and which one is better to use?

2nd Jun 2017, 12:14 PM
ketie
ketie - avatar
6 Answers
+ 4
Both can be called on functions, which they run in the context of the first argument. In call the subsequent arguments are passed in to the function as they are. The limitations of call become apparent when you want to write code that doesn't (or shouldn't) know the number of arguments. Apply expects the second argument to be an array that it unpacks as arguments for the called function.
2nd Jun 2017, 12:59 PM
Felipe Cruz
Felipe Cruz - avatar
+ 1
thanks^^
6th Jun 2017, 4:54 PM
ketie
ketie - avatar
0
hello
7th Jul 2017, 10:43 PM
bzhzbzg
0
hi
7th Jul 2017, 10:44 PM
bzhzbzg