Learnthisso you can use it effectively when you encounter it. Here's how to become great at JavaScript in less than 2 months If you’re stuck because of your lack of JavaScript skills, you can stop worrying now. We’ll help you become amazing at JavaScript— we have a course that can...
代码语言:javascript 代码运行次数:0 运行 AI代码解释 functionmultiply(a,b){'use strict';// enable the strict modeconsole.log(this===undefined);// => truereturna*b;}// multiply() function invocation with strict mode enabled// this in multiply() is undefinedmultiply(2,5);// => 10 当使...
上边的代码中,use strict 是写在 execute 函数体的头部,函数内部的 this 会是undefined。同时,因为 concat 是定义在 execute 内部,它也会继承严格模式。因此 concat('Hello', ' World!') 的调用,其内部的 this 也会指向 undefined。 一个单独 js 文件可能包含多个作用域,因此不同的作用域可能分别处于非严格模...
与其他语言相比,函数的 this 关键字在 JavaScript 中的表现略有不同,此外,在严格模式和非严格模式之间也会有一些差别。
理解this 就像在JavaScript广阔的领域中握住指南针。这不仅仅是为了弄清楚一个关键字;它是为了打开通往高级编码技巧和模式的大门。 为什么我们应该关心“this”? 普遍性:就像你无法逃避的流行曲调, this 在JavaScript中随处可见。从小脚本到庞大的Web应用程序,它都会显现出来。
https://www.codementor.io/@dariogarciamoya/understanding--this--in-javascript-du1084lyn 关于this in arrow function, 也可以看这个解释:https://stackoverflow.com/questions/63541194/meaning-of-enclosing-lexical-context-when-we-use-arrow-function-lexical-this...
Here's how to become great at JavaScript in less than 2 months If you’re stuck because of your lack of JavaScript skills, you can stop worrying now. We’ll help you become amazing at JavaScript— we have a course that can help you understand and use JavaScript easily. And we’re ...
Note: When usingthisinside a function with strict mode, you can useJavaScript Function call(). For example, 'use strict';this.name ='Jack';functiongreet(){console.log(this.name); } greet.call(this);// Jack Run Code When you passthiswith thecall()function,greet()is treated as the met...
function foo() { "use strict" console.log(this); undifined } foo() 2.“call()”和“apply()”中的this总是他们的第一个参数 var a = 10 var obj = { a: 20, foo: function () { "use strict" console.log(this); } } // When null | undefined, in non-strict mode, this points ...
严格模式 ‘use strict’; 如果在严格模式的情况下执行纯粹的函数调用,那么这里的的this并不会指向全局,而是undefined,这样的做法是为了消除 js 中一些不严谨的行为: 当然,把它放在一个立即执行函数中会更好,避免了污染全局: 作为对象的方法调用 当一个函数被当作一个对象的方法调用的时候: ...