【发布时间】:2016-06-01 13:26:22
【问题描述】:
当我在 Chrome 中运行此代码时,我得到一个 Uncaught TypeError: Cannot read property 'concat' of undefined
function _log()
{
'use strict'
[this].concat(Array.from(arguments)).forEach(
function (obj) { console.log(obj) }
)
}
_log('foo', 'bar');
我不明白为什么会这样。 [this] 怎么可能是未定义的?即使this 未定义,[this] 也应该是一个数组,不是吗?
一个有趣的细节是,当我从函数中删除 use strict 行时,错误消失并且代码按预期运行,将函数上下文和参数分别记录在新行上。
在我不知道的严格模式下使用关键字this 可能有什么特别之处吗?
谢谢。
【问题讨论】:
标签: javascript this strict-mode