Front-end see around corners JavaScript basics: This or?

Source: Internet
Author: User

In the previous section, we mentioned the question of this keyword, and added a very meaningful word: who called me and who I pointed to. Indeed, in JavaScript, by default, this points to a Window object that has already been initialized. So no matter how many global variables you have, the global function is appended to the Window object by default, so in this case, regardless of how this is used, the window object is searched for variables, functions, and so on.

In the actual encoding, the default for this can only be applied to scenarios where the business is relatively simple. However, in most business scenarios, this needs to change its point of reference to implement certain business logic. In this way, we have to dig deep into the deep.

As we mentioned in the previous section, the call method, the Apply method, and the Bind method all change the scope of this and also use some examples to demonstrate. But if you really want to put this this thoroughly understand, let's split into the following two sections to one by one: self-executing functions and closures.

Say self-executing function, I also in the last section about a little bit, nothing more than the function after the execution of the Add (); can be achieved. For example, the following method:

Front-end see around corners JavaScript basics: This or?

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.