What is the difference between call and apply in javascript?

Edit


I always forget the different of usage of "apply" and "call" in javascript. Today, from a stackoverflow page, I got an easy way to remember! 
A useful mnemonic is "A for array and C for comma."
The whole context is
The difference is that apply lets you invoke the function with arguments as an array; callrequires the parameters be listed explicitly. A useful mnemonic is "A for array and C for comma." 
See MDN's documentation on apply and call. 
Pseudo syntax:
theFunction.apply(valueForThis, arrayOfArgs) 
theFunction.call(valueForThis, arg1, arg2, ...)

further reading : http://stackoverflow.com/a/1986909/1109028




What is the difference between call and apply in javascript? What is the difference between call and apply in javascript? Reviewed by DF on 11:42:00 PM Rating: 5
©DF. Powered by Blogger.