Understand the Function. prototype. bind method in javascript, prototype. bind

Source: Internet
Author: User

Understand the Function. prototype. bind method in javascript, prototype. bind

When we are new to Javascript, we may not need to worry about function binding, but when we need to keep the context object this in another function, we will encounter corresponding problems, I have seen many people assign this value to a variable (such as self, _ this, And that), especially var that = this is the most common problem I have seen, in this way, you can use it after changing the environment. These are all possible, but there is also a better and more proprietary method, that is, using Function. prototype. bind, which will be explained in detail below.

Part 1: Problems to be Solved

Var myObj = {specialFunction: function () {}, anotherSpecialFunction: function () {}, getAsyncData: function (cb) {cb () ;}, render: function () {this. getAsyncData (function () {this. specialFunction (); this. anotherSpecialFunction () ;}}}; myObj. render ();

For more information, see

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.