更换
Object(obj)
Run Code Online (Sandbox Code Playgroud)
同
{}.constructor(obj)
Run Code Online (Sandbox Code Playgroud)
它们完全相同吗?
初步测试表明他们是.
为什么第二个版本传递jslint而不是第一个?
小智 5
以下是差异的摘要(取自jslinterrors):
// Overwrite the Object function.
window.Object = 10;
// Execution of the following will raise:
// "TypeError: number is not a function" (Chrome)
var x = new Object();
Run Code Online (Sandbox Code Playgroud)
var x = {};无论window.Object的状态如何,对象文字概念都会成功.