Tag:javascript
Article From:https://segmentfault.com/q/1010000012148225
Question:

`var num=[1,2,3]
var themax=Math.max.apply(Math, num);`
In this way of writing: two questions
1:apply()The two parameter is the scope of running the function, and the other is the parameter array.
Moreover, the max () function acquiescence is a string of values, but I still can not understand.
What is the use of the incoming Math object? Default Math.max () represents the max () method in the Math object, is not it a meaning?
Which step is this array converted to a string of values?

2.When my incoming object is null, the result is still running. Why?

Answer 0:

callI know the difference from apply
call(this, 1, 2, 3, …);
apply(this, [1, 2, 3, …]);
Apply is used to change the array into a parameter list, and the first this position is better to write null, because it does not pollute the other this context, which is a placeholder without practical significance.
You want to know the underlying principles need to see the source of the apply method, that is not the JavaScript category, we need to see the development source code.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *