Il metodo Object.getPrototypeOf()
restituisce il prototipo (ovvero il valore della proprietà interna [[Prototype]]
) dell'oggetto specificato.
Sintassi
Object.getPrototypeOf(obj)
Parametri
obj
- L'oggetto di cui si vuole ottenere il prototipo.
Esempi
var proto = {}; var obj = Object.create(proto); Object.getPrototypeOf(obj) === proto; // true
Note
Se il parametro obj non è un oggetto, nello standard ES5 il metodo innescherà un'eccezione TypeError
, mentre nello standard ES6 il parametro sarà assegnato forzatamente ad un Object
.
Object.getPrototypeOf("foo"); // TypeError: "foo" is not an object (ES5 code) Object.getPrototypeOf("foo"); // String.prototype (ES6 code)
Specifiche
Specifica | Stato | Commenti |
---|---|---|
ECMAScript 5.1 (ECMA-262) The definition of 'Object.getPrototypeOf' in that specification. |
Standard | Prima definizione. |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Object.getProtoypeOf' in that specification. |
Standard |
Compatibilità fra i Browser
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 5 | 3.5 (1.9.1) | 9 | 12.10 | 5 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? | ? |
Note specifiche su Opera
Anche se le vecchie versioni di Opera non supportano ancora il metodo Object.getPrototypeOf()
, comunque dalla versione 10.50 è stata implementata la proprietà non standard __proto__
.