[英]How do “Object()” and “new Object()” differ in JavaScript?
In JavaScript, what's the difference between 在JavaScript中,有什么区别
var x = Object();
and 和
var x = new Object();
? ?
This is pulled directly from the ECMAScript specification : 这是直接从ECMAScript规范中提取的:
When Object is called as a function rather than as a constructor, it performs a type conversion. 当Object作为函数而不是构造函数调用时,它执行类型转换。
When the Object function is called with no arguments or with one argument value, the following steps are taken: 如果在没有参数或具有一个参数值的情况下调用Object函数,则执行以下步骤:
If value is null, undefined or not supplied, create and return a new Object object exactly as if the standard built-in Object constructor had been called with the same arguments (15.2.2.1). 如果value为null,undefined或not provided,则创建并返回一个新的Object对象,就像使用相同的参数调用标准的内置Object构造函数一样(15.2.2.1)。
In Short: new Object([ value ])
简而言之:
new Object([ value ])
Return ToObject(value). 返回ToObject(值)。
[ ] Is A common way to mark a parameter as optional. []是将参数标记为可选的常用方法。
ToObject Is a very simple operation that is defined in section 9.9. ToObject是一个非常简单的操作,在第9.9节中定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.