Object.getPrototypeOf()

Resumen

El método Object.getPrototypeOf() devuelve el prototipo (es decir, el valor de la propiedad interna [[Prototype]]) del objeto especificado.

Sintaxis

Object.getPrototypeOf(obj)

Parámetros

obj

El objeto cuyo prototipo va a ser devuelto.

Valor Devuelto

El prototipo del objeto dado. Si no existen propiedades heredadas se devolverá null.

Ejemplos

js
var proto = {};
var obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; // true

Notas

En ES5, lanzará una excepción TypeError si el parámetro obj no es un objeto. en ES6, El parámetro será forzado a un Object.

js
> Object.getPrototypeOf('foo')
TypeError: "foo" is not an object  // ES5 code
> Object.getPrototypeOf('foo')
String.prototype                   // ES6 code

Especificaciones

Specification
ECMAScript Language Specification
# sec-object.getprototypeof

Compatibilidad con navegadores

BCD tables only load in the browser

Mira también