怎么做“对象()”和“new Object()” JavaScript有什么不同? [英] How do "Object()" and "new Object()" differ in JavaScript?

查看:100
本文介绍了怎么做“对象()”和“new Object()” JavaScript有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaScript中,有什么区别

In JavaScript, what's the difference between

var x = Object();

var x = new Object();

推荐答案

这是直接从 ECMAScript中提取的规范

调用Object时作为函数而不是构造函数,它执行类型转换。

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:


  1. 如果value为null,未定义或不提供
    ,则创建并返回一个新的
    Object对象,就像调用
    标准内置Object
    构造函数一样与
    相同的参数(15.2.2.1)。

  1. 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).

简而言之: 新对象([值])

返回ToObject(值)。

Return ToObject(value).



注意:



[] 是将参数标记为可选的常用方法。

Notes:

[ ] Is A common way to mark a parameter as optional.

ToObject 这是一个非常简单的操作,在第9.9节中定义。

ToObject Is a very simple operation that is defined in section 9.9.

这篇关于怎么做“对象()”和“new Object()” JavaScript有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆