Home > Web Front-end > JS Tutorial > body text

A brief discussion on the this pointer in Javascript_javascript skills

WBOY
Release: 2016-05-16 18:31:51
Original
989 people have browsed it

(1) Use this in the global execution environment to identify the Global object, which is the window object in the browser.
(2) When using this in a function execution environment, if the function is not obviously an attribute of a non-window object, but just defines a function, regardless of whether the function is defined in another function, in this function The this still identifies the window object. If the function is explicitly used as a property of a non-window object, then this in the function represents this object.

Copy code The 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 through the new operator, the function is treated as a constructor, and this points to The object created by the constructor.

For more details, please refer to
Javascript this pointer
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!