call, apply:
role:
1, change the This in the function, and take the value of the first parameter as this
of the current function 2, let the current function execute
For example: Fn.call (obj) makes the this in FN change to obj, and then makes the FN function execute
difference: When you pass parameters to a function, call is a pass, and apply is to put the parameters that need to be passed into an array, and pass in the
function name. apply ([This],[parameter1,parameter2 ...])
call/apply: The first argument writes who, this is who in the function, but there is a special case:
The first argument is who it is, Write null is NULL, write undefined is undefined, do not write is undefined
Applications for Call and apply:
Gets the maximum and minimum values in the array
var ary = [12, 25, 13, 26, 27, 59, 56];
The use of the Max and Min methods in mathematical functions is implemented by using the Apply method when executing, you need to pass the parameters as an array to pass in
var ary = [N, a, 56];var max = Math.max.apply (null, ary), var min = Math.min.apply (null, ary); console.log (min, max); 59
ecmascript--reference data type function about call and apply