What is the difference between using call
and apply
to invoke a function?
var func = function() {
alert(\'hello!\');
};
>
We can differentiate call and apply methods as below
CALL : A function with argument provide individually. If you know the arguments to be passed or there are no argument to pass you can use call.
APPLY : Call a function with argument provided as an array. You can use apply if you don't know how many argument are going to pass to the function.
There is a advantage of using apply over call, we don't need to change the number of argument only we can change a array that is passed.
There is not big difference in performance. But we can say call is bit faster as compare to apply because an array need to evaluate in apply method.