O construtor Object cria um wrapper de objeto.

Sintaxe

// Object initialiser or literal
{ [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] }

// Called as a constructor
new Object([value])

Parametros

nameValuePair1, nameValuePair2, ... nameValuePairN
Pares de nomes (strings) e valores (qualquer valor) em que o nome é separado do valor por dois pontos.
value
Qualquer valor.

Descrição

O construtor Object cria um wrapper de objeto para o valor fornecido. Se o valor for null ou undefined, ele criará e retornará um objeto vazio, caso contrário, retornará um objeto de um Type que corresponde ao dado valor. Se o valor já for um objeto, ele retornará o valor.

Quando chamado em um contexto não-construtor, o object se comporta de forma idêntica ao new Object ().

Veja também object initializer / literal syntax.

Propriedades do construtor Object

Object.length
Tem um valor de 1.
Object.prototype
Permite a adição de propriedades a todos os objetos do tipo Object.

Métodos do construtor Object

Object.assign()
Copia os valores de todas as propriedades próprias enumeráveis ​​de um ou mais objetos de origem para um objeto de destino.
Object.create()
Cria um novo objeto com o objeto e as propriedades do protótipo especificado.
Object.defineProperty()
Adiciona a propriedade nomeada descrita por um determinado descritor a um objeto.
Object.defineProperties()
Adiciona as propriedades nomeadas descritas pelos descritores fornecidos a um objeto.
Object.entries()
Retorna uma matriz contendo todos os pares [key, value] das próprias propriedades de string enumeráveis ​​de um determinado objeto.
Object.freeze()
Congela um objeto: outro código não pode excluir ou alterar nenhuma propriedade.
Object.fromEntries()
Retorna um novo objeto de um iterável de pares de valor-chave (reverso à Object.entries).
Object.getOwnPropertyDescriptor()
Retorna um descritor de propriedade para uma propriedade nomeada em um objeto.
Object.getOwnPropertyDescriptors()
Retorna um objeto contendo todos os descritores de propriedade para um objeto.
Object.getOwnPropertyNames()
Retorna uma matriz contendo os nomes de todas as propriedades enumeráveis ​​e não enumeráveis ​​do próprio objeto fornecido.
Object.getOwnPropertySymbols()
Retorna uma matriz de todas as propriedades de símbolo encontradas diretamente sobre um determinado objeto.
Object.getPrototypeOf()
Retorna o protótipo do objeto especificado.
Object.is()
Compara se dois valores são o mesmo valor. Equivale a todos os valores de NaN (que diferem da Comparação de Igualdade Abstrata e da Comparação de Igualdade Estrita).
Object.isExtensible()
Determina se a extensão de um objeto é permitida.
Object.isFrozen()
Determina se um objeto foi congelado.
Object.isSealed()
Determina se um objeto está selado.
Object.keys()
Retorna uma matriz contendo os nomes de todas as propriedades de string enumeráveis ​​do objeto fornecido.
Object.preventExtensions()
Impede qualquer extensão de um objeto.
Object.seal()
Impede que outro código exclua propriedades de um objeto.
Object.setPrototypeOf()
Define o protótipo (isto é, a propriedade interna [[Prototype]]).
Object.values()
Retorna uma matriz contendo os valores que correspondem a todas as propriedades de string enumeráveis ​​do próprio objeto.

Instâncias de Object e Object de protótipo de objeto

Todos os objetos em JavaScript são descendentes do Object; todos os objetos herdam métodos e propriedades de Object.prototype, embora eles possam ser substituídos. Por exemplo, protótipos de outros construtores substituem a propriedade constructor e fornecer seus próprios métodos toString(). As alterações no objeto de protótipo Object são propagadas para todos os objetos, a menos que as propriedades e os métodos sujeitos a essas alterações sejam substituídos na cadeia de protótipos.

Propriedades (enUS)

Object.prototype.constructor
Specifies the function that creates an object's prototype.
Object.prototype.__proto__
Points to the object which was used as prototype when the object was instantiated.
Object.prototype.__noSuchMethod__
Allows a function to be defined that will be executed when an undefined object member is called as a method.
Object.prototype.__count__
Used to return the number of enumerable properties directly on a user-defined object, but has been removed.
Object.prototype.__parent__
Used to point to an object's context, but has been removed.

Métodos (enUS)

Object.prototype.__defineGetter__()
Associates a function with a property that, when accessed, executes that function and returns its return value.
Object.prototype.__defineSetter__()
Associates a function with a property that, when set, executes that function which modifies the property.
Object.prototype.__lookupGetter__()
Returns the function associated with the specified property by the __defineGetter__() method.
Object.prototype.__lookupSetter__()
Returns the function associated with the specified property by the __defineSetter__() method.
Object.prototype.hasOwnProperty()
Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.
Object.prototype.isPrototypeOf()
Returns a boolean indicating whether the object this method is called upon is in the prototype chain of the specified object.
Object.prototype.propertyIsEnumerable()
Returns a boolean indicating if the internal ECMAScript [[Enumerable]] attribute is set.
Object.prototype.toSource()
Returns string containing the source of an object literal representing the object that this method is called upon; you can use this value to create a new object.
Object.prototype.toLocaleString()
Calls toString().
Object.prototype.toString()
Returns a string representation of the object.
Object.prototype.unwatch()
Removes a watchpoint from a property of the object.
Object.prototype.valueOf()
Returns the primitive value of the specified object.
Object.prototype.watch()
Adds a watchpoint to a property of the object.
Object.prototype.eval()
Used to evaluate a string of JavaScript code in the context of the specified object, but has been removed.

Excluindo uma propriedade de um objeto

Não há nenhum método em um Objeto para excluir suas próprias propriedades (por exemplo, como Map.prototype.delete()). Para isso, é necessário usar o operador delete.

Exemplos

Usando Object com tipos undefinednull

Os exemplos a seguir armazenam um Object vazio na variável "o":

var o = new Object();
var o = new Object(undefined);
var o = new Object(null);

Using Object to create Boolean objects

Os exemplos a seguir armazenam objetos Boolean na variável "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ções Status Comentário
ECMAScript 1st Edition (ECMA-262) Padrão Definição inicial. Implementado no JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)
The definition of 'Object' in that specification.
Padrão ------------------------------------------------
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Object' in that specification.
Padrão Adicionado Object.assign, Object.getOwnPropertySymbols, Object.setPrototypeOf e Object.is
ECMAScript Latest Draft (ECMA-262)
The definition of 'Object' in that specification.
Rascunho Adicionado  Object.entries, Object.values e Object.getOwnPropertyDescriptors.

Compatibilidade

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
prototypeChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
__count__
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
__noSuchMethod__
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 1 — 43IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 4 — 43Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
__parent__
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
__proto__
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
constructorChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
assignChrome Full support 45Edge Full support YesFirefox Full support 34IE No support NoOpera Full support 32Safari Full support 9WebView Android No support NoChrome Android Full support 45Edge Mobile Full support YesFirefox Android Full support 34Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 5.0nodejs Full support 4.0.0
createChrome Full support 5Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 11.6Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support 11.5Safari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
definePropertiesChrome Full support 5Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 11.6Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support 11.5Safari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
definePropertyChrome Full support 5Edge Full support YesFirefox Full support 4IE Full support 9
Notes
Full support 9
Notes
Notes Also supported in Internet Explorer 8, but only on DOM objects and with some non-standard behaviors.
Opera Full support 11.6Safari Full support 5.1
Notes
Full support 5.1
Notes
Notes Also supported in Safari 5, but not on DOM objects.
WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support 11.5Safari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
entriesChrome Full support 54Edge Full support 14Firefox Full support 47IE No support NoOpera Full support 41Safari Full support 10.1WebView Android Full support 54Chrome Android Full support 54Edge Mobile Full support YesFirefox Android Full support 47Opera Android Full support 41Safari iOS Full support 10.1Samsung Internet Android Full support 6.0nodejs Full support 7.0.0
Full support 7.0.0
Full support 6.5.0
Disabled
Disabled From version 6.5.0: this feature is behind the --harmony runtime flag.
freezeChrome Full support 6Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
fromEntriesChrome No support NoEdge No support NoFirefox Full support 63IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 63Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
getNotifier
DeprecatedNon-standard
Chrome No support 36 — 52Edge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
getOwnPropertyDescriptorChrome Full support 5Edge Full support YesFirefox Full support 4IE Full support 8Opera Full support 12Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
getOwnPropertyDescriptorsChrome Full support 54Edge Full support 15Firefox Full support 50IE No support NoOpera Full support 41Safari Full support 10WebView Android ? Chrome Android Full support 54Edge Mobile Full support YesFirefox Android Full support 50Opera Android ? Safari iOS ? Samsung Internet Android Full support 6.0nodejs Full support 7.0.0
Full support 7.0.0
Full support 6.5.0
Disabled
Disabled From version 6.5.0: this feature is behind the --harmony runtime flag.
getOwnPropertyNamesChrome Full support 5Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
getOwnPropertySymbolsChrome Full support 38Edge Full support YesFirefox Full support 36IE No support NoOpera Full support 25Safari Full support 9WebView Android Full support 38Chrome Android Full support 38Edge Mobile Full support YesFirefox Android Full support 36Opera Android Full support 25Safari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.12
getPrototypeOfChrome Full support 5Edge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support 12.1Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
isChrome Full support 30Edge Full support YesFirefox Full support 22IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.10
isExtensibleChrome Full support 6Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
isFrozenChrome Full support 6Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
isSealedChrome Full support 6Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
keysChrome Full support 5Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
observe
DeprecatedNon-standard
Chrome No support 36 — 52Edge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
preventExtensionsChrome Full support 6Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
__defineGetter__
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support 1
Notes
Full support 1
Notes
Notes Starting with Firefox 48, this method can no longer be called at the global scope without any object. A TypeError will be thrown otherwise. Previously, the global object was used in these cases automatically, but this is no longer the case.
IE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
__defineSetter__
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support 1
Notes
Full support 1
Notes
Notes Starting with Firefox 48, this method can no longer be called at the global scope without any object. A TypeError will be thrown otherwise. Previously, the global object was used in these cases automatically, but this is no longer the case.
IE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
__lookupGetter__
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
__lookupSetter__
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
eval
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
hasOwnPropertyChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
isPrototypeOfChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
propertyIsEnumerableChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
toLocaleStringChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
toSource
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox Full support 1IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 4Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
toStringChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
unwatch
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 1 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 4 — 58Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
valueOfChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
watch
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 1 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 4 — 58Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
sealChrome Full support 6Edge Full support YesFirefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
setPrototypeOfChrome Full support 34Edge Full support YesFirefox Full support 31IE Full support 11Opera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 31Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support 0.12
unobserve
DeprecatedNon-standard
Chrome No support 36 — 52Edge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
valuesChrome Full support 54Edge Full support 14Firefox Full support 47IE No support NoOpera Full support 41Safari Full support 10.1WebView Android Full support 54Chrome Android Full support 54Edge Mobile Full support YesFirefox Android Full support 47Opera Android Full support 41Safari iOS Full support 10.3Samsung Internet Android Full support 6.0nodejs Full support 7.0.0
Full support 7.0.0
Full support 6.5.0
Disabled
Disabled From version 6.5.0: this feature is behind the --harmony runtime flag.

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
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.

Veja também

Etiquetas do documento e colaboradores

Etiquetas: 
Última atualização por: UPPERCASEuser,