What is the difference between call and apply in javascript?
EditI 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 thatapplylets you invoke the function withargumentsas 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, ...)
What is the difference between call and apply in javascript?
Reviewed by DF
on
11:42:00 PM
Rating: