The use of the "non-change this" for apply

Source: Internet
Author: User

When it comes to apply, we all know that change this point, also will immediately and call together, MDN official online also said:

In fact, when we use call and apply, we all think of their function of changing this function,

As the MDN says, there is only one difference between apply and call: The two parameters of the Apply method accept the parameter array!

In other words: The second "parameter array" of apply will eventually be called by the function called apply;

So we can also take advantage of this feature to do an array of scattered operations, as described in MDN:

Of course we can also use ES6 's expansion statement, as follows:

The reason to write this article is to warn yourself: think not too limited , as if you feel that apply can only be used to change the point of this function. When we look at Math.max. Apply(null, arr) This kind of circle, in fact, this is omitted to expand the operation of the array.

When you find doubt, you can empty your knowledge of the past and re-read the API. Think again about the problem.

Just like you do physics problems, in the mind never remember questions, the brain only need to remember the formula and principle, all the topics are to think analysis and answer, Status quo!! Instead of classifying the topic, we can recall the problem solving method of the modified type.

The use of the "non-change this" for apply

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.