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
The use of$(this), which is jQuery’s syntax for thethiskeyword in JavaScript, is used inside an anonymous function, and the anonymous function is executed in the button’s click () method. The reason(this)isboundtothebuttonobjectisbecausethejQuerylibrarybinds(this)isboundtothebuttonobjectisbeca...
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...
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...
The "this" is special keyword in JavaScript. It is used to refer to the object on which a method is being invoked. So what is the the value of "this" in a given context ? We will state some basic steps. Do not worry if you do not understand it. Just read it once. We will re...
http://www.ruanyifeng.com/blog/2010/04/using_this_keyword_in_javascript.html 分情况讨论。 情况一:纯粹的函数调用 这是函数的最通常用法,属于全局性调用,因此this就代表全局对象Global。 var x = 1; function test(){ this.x = 0; ...
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 ...
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....
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. ...
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...