Read What is 'this' in JavaScript? and learn with SitePoint. Our web development and design tutorials, courses, and books will teach you HTML, CSS, JavaScript, PHP, Python, and more.
Compared to other languages, thethiskeyword acts differently in JavaScript. It is one of the most common JavaScript keywords. As confusing as it can be, it is a fundamental concept because it allows for flexibility, reusing a function in multiple contexts. What Is the ‘This’? When you invo...
JavaScript 'this' keyword By: Rajesh P.S.In JavaScript, the this keyword is a special context-sensitive variable that refers to the current execution context or the object that a function is bound to at runtime. The value of this depends on how a function is invoked, and it plays a ...
}// 方法-介绍你自己(使用this编写)Person.prototype.introduceYourselfWithThis=function() {if(Object.hasOwnProperty.call(this,'name')) {return`My name is${this.name}`; }return`I have no name`; }// 方法-介绍你自己(不使用this编写)Person.prototype.introduceYourself=function(invoker) {if(Object...
javascript 中的关键词 this 代指 执行上下文(Execution Contexts),函数作用域中的this,理解上来说是指调用这个函数的对象。相信以下几个实验可以加深对this关键字的理解。 实验一:全局下的this 全局作用域下的函数里面的this,显然等于全局对象window function test(){ ...
代码语言:javascript 代码运行次数:0 运行 AI代码解释 //假设我们定义一个人的类functionPerson(name){}// 方法-介绍你自己(使用this编写)Person.prototype.introduceYourselfWithThis=function(){if(Object.hasOwnProperty.call(this,'name')){return`My name is${this.name}`;}return`I have no name`;}// ...
About “this” P1:如何使用this? this 实际上是在函数被调用时发生的绑定,它指向什么完全取决于函数在哪里被调用。 这话说起来容易,理解起来缺常常出现问题。请看如下几段代码 var a =1; var obj = { a = 0, say:function(){ console.log(this.a) } ...
JavaScript - what is "this"? this是什么? Core func(p1,p2)// 等同于func.call(undefined,p1,p2) this 就是call第一个参数,是一个context。
The "this" parameter in JavaScript is like that oddly concealed obstacle on a path that keeps tripping people.
JavaScript StringsStrings store text. Strings are written inside quotes. You can use single or double quotes:Example var carname = "Volvo XC60"; // Double quotes var carname = 'Volvo XC60'; // Single quotes Try it Yourself » The length of a string is found in the built in property...