JavaScript Learning Lesson Five this, call, apply

Source: Internet
Author: User

The This object is bound to a function-based execution environment in the run, in the global function, this equals window, and when the function is called as a method of an object, this is equal to that object

This means that the This keyword refers to the caller.

Call, apply example:

1. Simple usage: Bind some functions for passing parameters, calling

2. Used to extend the scope used for function run:

JS does not have a block-level scope concept:

Example of a feature that emulates a block-level scope for a high-level language:

By using the anonymous function self-executing implementation:

Closures:

Closures Example:

JavaScript Learning Lesson Five this, call, apply

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.