The ecmascript Specification defines two methods for all functions: Apply () and call (). You can use these two methods to call a function just like calling methods of other objects.
Call ():
The first parameter of call () is the object of the function to be called. In the function body, this parameter is the value of the keyword "this. The remaining parameters of call () are the parameter values passed to the function to be called. For example, to pass two numbers to function f () and call it as the method of object o, you can use the following code:
F. Call (O, 1, 2 );
This is similar to the following code:
O. M = f; O. M (1, 2); Delete o. m;
Apply ():
The first parameter of apply () is also the object of the function to be called, except that the parameter to be passed to the function is specified by the array:
F. Apply (O, [1, 2]);
For example, to find the maximum number in a number array, you can use the apply () method to pass the array element to the math. Max () function:
<HTML>