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 referenc
/* 非严格模式 */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...
functiongreet(){// this inside function// this refers to the global objectconsole.log(this); } greet();// Window {} Run Code 3. this Inside Constructor Function In JavaScript,constructor functionsare used to create objects. When a function is used as a constructor function,thisrefers to th...
function Person( 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. //严格模式下,函数中的this是undefined "use strict" function f(){ console.log(this); //undefined } f();...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions D:\GPUGO\MP\wepy\mpBMCwepy\src\utils\wxRequest.js wepy bui
「In most cases, the value of this is determined by how a function is called.」「在大多数的情况下,this 其值取决于函数的调用方式。」好,如果上面两行就看得懂的话那么就不用再往下看了,Congratulations!… 我想应该不会,至少我光看这两行还是不懂。先来看个例子吧:var getGender = function()...
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...
Arrow functions (Function) – JavaScript 中文开发手册,[Arrowfunctions(Function)-JavaScript中文开发手册箭头函数表达式的语法比函数表达式更短,并且不绑定自己的this,arguments,super或 new.target。这些函数表达式最适合用于非方法函数,并且它们不能用作构造函数
英文| https://blog.bitsrc.io/where-exactly-does-this-point-to-in-javascript-2be1e3fad1fd 函数中的 this 在调用时是绑定的,完全取决于函数的调用位置(即函数的调用方式)。要知道 this 指向什么,你必须知道相关函数是如何被调用的。 1、Global...
代码语言:javascript 代码运行次数:0 运行 AI代码解释 functionexecute(){'use strict';functionconcat(str1,str2){// the strict mode is enabled tooconsole.log(this===undefined);// => truereturnstr1+str2;}console.log(this===undefined);// => true// concat() is invoked as a function in st...