当我在 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
在我不知道的严格模式下使用关键字可能有什么特别之处吗?
谢谢。