Object 构造函数 creates an object wrapper for the given value.

  • If the value is null or undefined , it will create and return an empty object.
  • Otherwise, it will return an object of a Type that corresponds to the given value.
  • If the value is an object already, it will return the value.

When called in a non-constructor context, Object behaves identically to new Object() .

句法

new Object()
new Object(value)
					

参数

value

Any value.

范例

Creating a new Object

let o = new Object()
o.foo = 42
console.log(o)
// Object { foo: 42 }
					

使用 Object given undefined and null types

The following examples store an empty Object object in o :

let o = new Object()
					
let o = new Object(undefined)
					
let o = new Object(null)
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'Object constructor' in that specification.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
Object() 构造函数 Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: