*js Core: Call, apply, and bind

Source: Internet
Author: User

1.

var func=function(a,b,c) {        console.log ([a,b,c]);    };  Func.apply (null, [I/n]); //  [Func.call](null, N/a); // [Func.bind](null, N/a);  // No output func.bind (null, N/a) ();    // [Func.bind](null) (2,3,4)  //[2,3,4]

Analytical:

When using apply or call, if we pass in the first argument to NULL, the this in the body of the function points to the default host object, which is window in the browser.

Apply and call are just the arguments passed in in the same form as the others. But bind is different: when call or apply is called before, the function runs directly, but Bind does not run, but instead returns a function of the binding context and this always points to the first argument in the bind parenthesis.

2.

Call, apply, and bind have 2 main functions:

① change the direction of this;

② ways to borrow other objects

*js Core: Call, apply, and bind

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.