This pointer in Javascript

Source: Internet
Author: User

(1) use this in the Global execution environment to identify the Global object, which is the window object in the browser.
(2) when this is used in the function execution environment, if the function does not explicitly act as an attribute of a non-window object, but only defines the function, whether this function is defined in another function or not, this in this function still identifies the window object. If the function is displayed as a non-window object attribute, this in the function indicates this object.
Copy codeThe Code is as follows:
Var o = new Object;
O. func = function ()
{
Alert (this = o ));
(Function (){
Alert (this = window ));
}
)();
}
O. func ();

(3) When a function is called using the new operator, the function is treated as a constructor. this points to the object created by the constructor.

For more details, refer
Javascript this pointer

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.