This translation is incomplete. Please help translate this article from English
o construtor Object cria um wrapper de objeto.
Sintaxe
// Object initialiser or literal
{ [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] }
// Called as a constructor
new Object([value])
Parâmetros
nameValuePair1, nameValuePair2, ... nameValuePairN- Pairs of names (strings) and values (any value) where the name is separated from the value by a colon.
value- Any value.
Descrição
The Object constructor 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().
See also the object initializer / literal syntax.
Propriedades de um construtor Object
Object.length- Tem um valor de 1.
Object.prototype- Permite a adição de propriedades para todos os objetos do tipo Object.
Métodos de um construtor Object
Object.assign()- Copies the values of all enumerable own properties from one or more source objects to a target object.
Object.create()- Creates a new object with the specified prototype object and properties.
Object.defineProperty()- Adds the named property described by a given descriptor to an object.
Object.defineProperties()- Adds the named properties described by the given descriptors to an object.
Object.entries()- Returns an array containing all of the
[key, value]pairs of a given object's own enumerable string properties. Object.freeze()- Freezes an object: other code can't delete or change any properties.
Object.fromEntries()- Returns a new object from an iterable of key-value pairs (reverses
Object.entries). Object.getOwnPropertyDescriptor()- Returns a property descriptor for a named property on an object.
Object.getOwnPropertyDescriptors()- Returns an object containing all own property descriptors for an object.
Object.getOwnPropertyNames()- Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties.
Object.getOwnPropertySymbols()- Returns an array of all symbol properties found directly upon a given object.
Object.getPrototypeOf()- Returns the prototype of the specified object.
Object.is()- Compares if two values are the same value. Equates all NaN values (which differs from both Abstract Equality Comparison and Strict Equality Comparison).
Object.isExtensible()- Determines if extending of an object is allowed.
Object.isFrozen()- Determines if an object was frozen.
Object.isSealed()- Determines if an object is sealed.
Object.keys()- Returns an array containing the names of all of the given object's own enumerable string properties.
Object.preventExtensions()- Prevents any extensions of an object.
Object.seal()- Prevents other code from deleting properties of an object.
Object.setPrototypeOf()- Sets the prototype (i.e., the internal
[[Prototype]]property). Object.values()- Returns an array containing the values that correspond to all of a given object's own enumerable string properties.
Instâcias de Object e objeto protótipo Object
All objects in JavaScript are descended from Object; all objects inherit methods and properties from Object.prototype, although they may be overridden. For example, other constructors' prototypes override the constructor property and provide their own toString() methods. Changes to the Object prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain.
Propriedades
Métodos
Deleting a property from an object
There isn't any method in an Object itself to delete its own properties (e.g. like Map.prototype.delete()). To do so one has to use the delete operator.
Exemplos
Using Object given undefined and null types
The following examples store an empty Object object in o:
var o = new Object();
var o = new Object(undefined);
var o = new Object(null);
Using Object to create Boolean objects
The following examples store Boolean objects in o:
// equivalent to o = new Boolean(true); var o = new Object(true);
// equivalent to o = new Boolean(false); var o = new Object(Boolean());
Especificações
| Especificação | Estado | Comentário |
|---|---|---|
| ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.0. |
| ECMAScript 5.1 (ECMA-262) The definition of 'Object' in that specification. |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Object' in that specification. |
Standard | Added Object.assign, Object.getOwnPropertySymbols, Object.setPrototypeOf, Object.is |
| ECMAScript (ECMA-262) The definition of 'Object' in that specification. |
Living Standard | Added Object.entries, Object.values and Object.getOwnPropertyDescriptors. |
Compatibilidade de navegador
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Object | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support 3 | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Object() constructor | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support 3 | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
assign | Chrome Full support 45 | Edge Full support 12 | Firefox Full support 34 | IE No support No | Opera Full support 32 | Safari Full support 9 | WebView Android Full support 45 | Chrome Android Full support 45 | Firefox Android Full support 34 | Opera Android Full support 32 | Safari iOS Full support 9 | Samsung Internet Android Full support 5.0 | nodejs Full support 4.0.0 |
constructor | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support 4 | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
create | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 11.6 | Safari Full support 5 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
__defineGetter__ | Chrome Full support 1 | Edge Full support 12 | Firefox
Full support
1
| IE Full support 11 | Opera Full support 9.5 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
defineProperties | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 11.6 | Safari Full support 5 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
defineProperty | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 4 | IE
Full support
9
| Opera Full support 11.6 | Safari
Full support
5.1
| WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS
Full support
6
| Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
__defineSetter__ | Chrome Full support 1 | Edge Full support 12 | Firefox
Full support
1
| IE Full support 11 | Opera Full support 9.5 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
entries | Chrome Full support 54 | Edge Full support 14 | Firefox Full support 47 | IE No support No | Opera Full support 41 | Safari Full support 10.1 | WebView Android Full support 54 | Chrome Android Full support 54 | Firefox Android Full support 47 | Opera Android Full support 41 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 6.0 | nodejs
Full support
7.0.0
|
freeze | Chrome Full support 6 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
fromEntries | Chrome Full support 73 | Edge Full support 79 | Firefox Full support 63 | IE No support No | Opera Full support 60 | Safari Full support 12.1 | WebView Android Full support 73 | Chrome Android Full support 73 | Firefox Android Full support 63 | Opera Android No support No | Safari iOS Full support 12.2 | Samsung Internet Android No support No | nodejs Full support 12.0.0 |
getOwnPropertyDescriptor | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 4 | IE
Full support
9
| Opera Full support 12 | Safari Full support 5 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getOwnPropertyDescriptors | Chrome Full support 54 | Edge Full support 15 | Firefox Full support 50 | IE No support No | Opera Full support 41 | Safari Full support 10 | WebView Android Full support 54 | Chrome Android Full support 54 | Firefox Android Full support 50 | Opera Android Full support 41 | Safari iOS Full support 10 | Samsung Internet Android Full support 6.0 | nodejs
Full support
7.0.0
|
getOwnPropertyNames | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getOwnPropertySymbols | Chrome Full support 38 | Edge Full support 12 | Firefox Full support 36 | IE No support No | Opera Full support 25 | Safari Full support 9 | WebView Android Full support 38 | Chrome Android Full support 38 | Firefox Android Full support 36 | Opera Android Full support 25 | Safari iOS Full support 9 | Samsung Internet Android Full support 3.0 | nodejs Full support 0.12 |
getPrototypeOf | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 12.1 | Safari Full support 5 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12.1 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
hasOwnProperty | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support 5 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
is | Chrome Full support 30 | Edge Full support 12 | Firefox Full support 22 | IE No support No | Opera Full support 17 | Safari Full support 9 | WebView Android Full support ≤37 | Chrome Android Full support 30 | Firefox Android Full support 22 | Opera Android Full support 18 | Safari iOS Full support 9 | Samsung Internet Android Full support 2.0 | nodejs Full support 0.10 |
isExtensible | Chrome Full support 6 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
isFrozen | Chrome Full support 6 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
isPrototypeOf | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 9 | Opera Full support 4 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
isSealed | Chrome Full support 6 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
keys | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
__lookupGetter__ | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 11 | Opera Full support 9.5 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
__lookupSetter__ | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 11 | Opera Full support 9.5 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
preventExtensions | Chrome Full support 6 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
propertyIsEnumerable | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support 4 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
__proto__ | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 11 | Opera Full support 10.5 | Safari Full support 3 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
seal | Chrome Full support 6 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setPrototypeOf | Chrome Full support 34 | Edge Full support 12 | Firefox Full support 31 | IE Full support 11 | Opera Full support 21 | Safari Full support 9 | WebView Android Full support 37 | Chrome Android Full support 34 | Firefox Android Full support 31 | Opera Android Full support 21 | Safari iOS Full support 9 | Samsung Internet Android Full support 2.0 | nodejs Full support 0.12 |
toLocaleString | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support 4 | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toSource | Chrome No support No | Edge No support No | Firefox
No support
1 — 74
| IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android Full support 4 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
toString() | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support 3 | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
valueOf | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support 3 | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
values | Chrome Full support 54 | Edge Full support 14 | Firefox Full support 47 | IE No support No | Opera Full support 41 | Safari Full support 10.1 | WebView Android Full support 54 | Chrome Android Full support 54 | Firefox Android Full support 47 | Opera Android Full support 41 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 6.0 | nodejs
Full support
7.0.0
|
Legend
- Full support
- Full support
- No support
- No support
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.