猿问

怎么理解严格模式下this

JavaScript高级程序设计中有下面这一句话:

在严格模式下,未指定环境对象而调用函数,则 this 值不会转型为 window。 除非明确把函数添加到某个对象或者调用 apply()或 call(),否则 this 值将是 undefined。

我进行了如下的尝试,希望能重点解释setTimeout和全局函数这三个中的this.

"use strict";
(function(){    console.log(this)//undefined})();

!function(){    console.log(this)//undefined}();

setTimeout(function(){    console.log(this) //window},0);function a(){    console.log(this);
}
a(); //undefined


慕婉清6462132
浏览 414回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答