In other words, arrow functions treat this like any other lexical variable. 翻译:换句话说,箭头函数对待this就像对待任何其他词法变量一样 If you use a this inside an arrow function, it behaves exactly as any other variable reference, which is that the scope chain is consulted to find a function...
/* 非严格模式 */functionf1() {returnthis; }console.log(f1() ===window);//true// in node;console.log(f1() ===global);//true/* 严格模式 */functionf2() {'use strict'returnthis; }console.log(f1() ===undefined);//true call / apply / bind 改变this的指向 call / apply call和ap...
function Person( name){ this.name = name; this.x=function(){ return this; } } let p = new Person("mcgrady"); console.log(p===p.x()) //true 1. 2. 3. 4. 5. 6. 7. 8. 9. AI检测代码解析 //严格模式下,函数中的this是undefined "use strict" function f(){ console.log(this...
A function's this keyword behaves a little differently in JavaScript compared to other languages. It also has some differences between strict mode and non-strict mode. JavaScript是一门比较奇特的语言,它的this与其他语言不一样,并且它的取值还取决于代码是否为严格模式("use strict")。 this的值是什么?
In JavaScript,constructor functionsare used to create objects. When a function is used as a constructor function,thisrefers to the object inside which it is used. For example, functionPerson(){this.name ='Jack';console.log(this); }letperson1 =newPerson();console.log(person1.name); ...
An Arrow Function does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, this, or new.target within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immed...
「In most cases, the value of this is determined by how a function is called.」「在大多数的情况下,this 其值取决于函数的调用方式。」好,如果上面两行就看得懂的话那么就不用再往下看了,Congratulations!… 我想应该不会,至少我光看这两行还是不懂。先来看个例子吧:var getGender = function()...
js in depth: arrow function & prototype & this & constructor 1. proptotype bug const log = console.log; // 1. constructor bug const func = () => { = `xgqfrms`; title = `arrow function`; log(``, ); }; log(`\nfunc`, func); ...
英文| https://blog.bitsrc.io/where-exactly-does-this-point-to-in-javascript-2be1e3fad1fd 函数中的 this 在调用时是绑定的,完全取决于函数的调用位置(即函数的调用方式)。要知道 this 指向什么,你必须知道相关函数是如何被调用的。 1、Global...
can be translated into a vague approximation of the arrow syntax in ES5: functionNinja(){this.whoAmI=function(){returnthis;}.bind(this);} 在问题1中的结果ninja2.whoAmI() === ninja1也就得到了解释。 所以说,书中的话并不是那么的准确:arrow functions don’t get their own implicit this parame...