JS to call Apply bind understanding

Source: Internet
Author: User

Please refer to http://www.cnblogs.com/xljzlw/p/3775162.html
Call apply
var MTT = { name: "MTT", sayhello:function (age) { console.log ("Hello, I Am", this.name + "+ Age" years Old ");} ; var xjs = { name: "XJS",
};mtt.sayhello (24); Hello, I am zlw years old

The Apply parameter needs to be in the form of an array, and the call parameter needs to be separated by commas 24,25
MTT Sayhello.call (XJS, 24);   Hello, I am xjs years old
MTT sayhello.apply (XJS, [24]); Hello, I am xjs years old

The arguments that the bind method passes to the calling function can be listed individually or in an array. The most significant difference between the bind method and call, apply is the function that returns a binding context
//hello, I am xlj years old //hello, I am xlj years old

Bind
var bind = Function.prototype.call.bind (Function.prototype.bind), var zlw = {name: "ZLW"};function Hello () {  // Hello, I am ZLW

JS to call Apply bind understanding

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.