Specification ECMAScript® 2026 Language Specification # sec-this-keyword 浏览器兼容性 参见 严格模式 globalThisHelp improve MDN Was this page helpful to you? YesNoLearn how to contribute. This page was last modified on 2025年4月13日 by MDN contributors. View this page on GitHub • Report ...
In JavaScript,thiskeyword refers to theobjectwhere it is called. 1. this Inside Global Scope Whenthisis used alone,thisrefers to the global object (windowobject in browsers). For example, leta =this;console.log(a);// Window {}this.name ='Sarah';console.log(window.name);// Sarah Run C...
The very first thing to understand when we're talking about this-keyword is really understand what's the purpose of the this-keyword is, or why we even have this-keyword in JavaScript. What the this-keyword allows us to do, is it allows us to reuse functions with different contexts, or...
In JavaScript, as in most object-oriented programming languages,thisis a special keyword that is used within methods to refer to the object on which a method is being invoked. ——jQuery Fundamentals (Chapter 2), by Rebecca Murphey 值得注意,该关键字在Javascript中和执行环境,而非声明环境有关。
(转)JavaScript中的this关键字,http://yanhaijing.com/javascript/2014/04/30/javascript-this-keyword/“this”关键字是JavaScript中广泛应用的一种特性,但它经常也是这门语言中最容易混淆和误解的特性。“this”的实际意义是什么?它是如何求值的?本文试图以清晰的方
In JavaScript, thethiskeyword refers to anobject. Thethiskeyword refers todifferent objectsdepending on how it is used: In an object method,thisrefers to theobject. Alone,thisrefers to theglobal object. In a function,thisrefers to theglobal object. ...
http://www.ruanyifeng.com/blog/2010/04/using_this_keyword_in_javascript.html 分情况讨论。 情况一:纯粹的函数调用 这是函数的最通常用法,属于全局性调用,因此this就代表全局对象Global。 var x = 1; function test(){ this.x = 0; ...
JavaScript In the example above, when we passobj.greetingas a callback to the functionsayHello(), itsthiskeyword loses itsthisbinding toobjand points to the global object.this.greetis not referring toobj—instead it is referring to the global object. This can be solved by using thebind()me...
也许你在其他面向对象的编程语言曾经看过this,也知道它会指向某个构造器(constructor)所建立的对象。但事实上在JavaScript里面,this所代表的不仅仅是那个被建立的对象。先来看看ECMAScript 标准规范对this 的定义:「The this keyword evaluates to the value of the ThisBinding of the current execution context.」...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call bind Thebind()method creates a new function that, when called, has itsthiskeyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called....