【发布时间】:2023-03-24 20:04:01
【问题描述】:
看起来当我在某些非严格函数func 上使用func.call(12) 时,它将使用this = new Number(12) 而不是this = 12(请参阅下面的sn-p)。我注意到因为typeof this 等于'object' 而不是'number'。
这是预期的行为吗?有什么办法解决吗?
function a() {
return this;
}
function b() {
'use strict';
return this;
}
const x = a.call(12);
console.log(typeof x);
console.log(x);
console.log(x + 3);
const y = b.call(12);
console.log(typeof y);
console.log(y);
console.log(y + 3);
【问题讨论】:
标签: javascript node.js