"JavaScript" [bind,call,apply] (function cal () {} ()); declaring the function to execute immediately

Source: Internet
Author: User

---restore content starts---

1. js function calls have 4 modes: Method invocation, normal function call, constructor function call, Apply/call call.
At the same time, no matter what function call except for the formal parameters that you define when you declare, you will automatically add 2 parameters, respectively this and arguments


2, the Apply:apply function receives 2 parameters, the first one is passed to this function to bind the value of this, the second is a parameter
Array.

Call and apply exist in order to change the binding of this.
Note: The difference is that the call is followed by an indeterminate argument, not an array.
Look at the code:

    function A (xx, yy) {             alert (xx, yy);             Alert (this);             alert (arguments);    }    A.apply (null, [5, +]);    A.call (null

3. Call and apply will execute the function immediately, and the second bind will not, it will generate a new function.
Other and call look, see the code:

var m = {            "x": 1    };     function foo (y) {        alert (this. x+ y);    }    Foo.apply (M, [5]);     5);     var foo1 = Foo.bind (M, 5);    

Clairvoyant

Source: http://rangercyh.blog.51cto.com

"JavaScript" [bind,call,apply] (function cal () {} ()); declaring the function to execute immediately

Related Article

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.