Math.min.apply (Math,arr) This method is used to find the smallest value in an array, which puzzles me, and I don't know why the first parameter applied to the Math object is passed back in.
"JavaScript advanced Programming" said: in order to correctly set the value of this.
This is not a good explanation, at least for the present stage of me.
(1) to the object-oriented, I first studied the Math object, from the words "javascript",
The Math is a little different form the other built-in objects, because it cannot be used as a constructor to create objects.< c1> It is just a collection of functions and constants.
This seems to tell us that Math is an object, that Min and Max are its methods, and that both Min and Max accept parametric forms, Math.min (NUM1, num2, num3, ...) That's all.
(2) but Math.min.apply (Math,arr) This strange wording is what. Well, we need to look at the second piece, the use of apply.
What is the role of call and apply? In addition to changing the this point of the function, what else. ---Apply can change the form passed to the function parameter
As you can see from the MDN, this is a magical part of apply.
Another key point to understand:
The first parameter of apply, can not be ignored ...
If the IS-a function in non-strict mode code, null and undefined would be replaced with the global object, and Primi tive values would be boxed
Summary: For the normal function FN,
function fn (Arg1,arg2,arg3,...) {
//....
}
FN (1,2,3)
Fn.apply. (null,[1,2,3])
Apply changes the incoming form of the parameter