JavaScript must be known (10) call apply bind usage instructions _javascript tips

Source: Internet
Author: User

Call

Each func will inherit call apply and other methods.

function print (mesage)
{
console.log (mesage);
return mesage;
}

Call (Thisagr,agr1,agr2 ...), the first pass of a context. The number of arguments is followed.

Apply

Apply (THISAGR,[AGR1,AGR2]), the Apply method is the same as call usage, except that the parameters passed are different.

function print (a,b)
{
Console.log (a + b);
}

Bind

Bind is to bind a function to a touch object.

<script>
function f (y) {alert (this.x + y);}
var o = {x:};
var g= f.bind (o);
g ();//

Summary

Calls to the Apply function are the same as direct use of function calls.

Call apply can also mimic the bind method.

<script>
function f (y) {alert (this.x + y);}
var o = {x:};
F.call (o,);//
f.apply (o, []);

The above is a small set to the introduction of JavaScript must Know (10) call apply bind the relevant knowledge of the use of the instructions, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.