小编syd*_*uki的帖子

为什么 setTimeout 中的回调即使在严格模式下也会有 this == Window ?

我现在正在学习 JS,不明白为什么“use strict”指令不适用于 setTimeout 的回调?据我所知,对于 use strict 它应该是未定义的,但始终具有全局对象。

function f() {
    'use strict'
    console.log(this === window)
}

function g() {
    console.log(this === window)
}

setTimeout(g,1000) // expect true, have true
setTimeout(f,1000) // expect false, have true
Run Code Online (Sandbox Code Playgroud)

javascript settimeout

5
推荐指数
1
解决办法
302
查看次数

标签 统计

javascript ×1

settimeout ×1