简体   繁体   English

在Javascript ES5和ES6中,如何严格影响此关键字在Function对象的调用和应用方法的上下文中

[英]How does use strict impact this keyword in the context of call and apply method of a Function object in Javascript ES5 and ES6

I want know the concept of this in use strict mode , in the context of call and apply method of a Function object in Javascript ES5 and ES6. 我想知道在使用严格模式的概念,在通话的情况下,并应用在Javascript ES5和ES6 Function对象的方法。 A good example with explanation will be highly appreciated. 一个很好的例子和解释将不胜感激。

If a function is strict , its this value is not converted to an object but kept as it is. 如果函数为strict ,则this值不会转换为对象,而是保持不变。 For non-strict functions, this is always converted to an object (unless it is null or undefined of course): 对于非严格的功能, this总是被转换为一个对象(除非它是nullundefined当然):

 function foo() { console.log(typeof this); } function foo_strict() { "use strict"; console.log(typeof this); } foo.call(42); foo_strict.call(42); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM