Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
What does getPrototypeOf of a Class point to?
Object.getPrototypeOf(..)

returns the prototype (i.e. the value of the internal [[Prototype]] property) of the specified object. so, the below makes sense

const prototype1 = {};
const object1 = Object.create(prototype1);

console.log(Object.getPrototypeOf(object1) === prototype1); // logs true

Even this looks fine

function fn() {
}
Object.getPrototypeOf(fn) == Function.prototype // logs true

But I am kind of confused why

Object.getPrototypeOf(Object) == Function.prototype // logs true

Please explain

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Some points to consider:

Object is a function

It can be used to convert a primitive to an object. Like Object("test") will create a String instance.

There is a constructor for functions

The constructor for functions is Function. It is not commonly done, but you can create a function by calling this constructor. For example: new Function("alert('test')") returns a function that when called will display an alert.

Functions which are created with function statements, expressions, arrow function syntax,... also have as constructor this Function. So for instance, eval.constructor === Function is a true expression. The same goes for Object.constructor === Function. You can do this for any function.

Where to find the a function's prototype object?

Like every constructor, Function has a prototype property. That object defines the prototype properties and methods that all functions inherit. We can find that prototype object via Function.prototype, or we can find it by taking a Function instance (i.e. a function), and getting its prototype object. This we do by calling Object.getPrototypeOf on a specific function.

Equalities

And so we can see that all of the following are equal:

var a = Object.getPrototypeOf(eval);
var b = Object.getPrototypeOf(parseInt);
var c = Object.getPrototypeOf(function () {});
var d = Object.getPrototypeOf(RegExp);
var e = Object.getPrototypeOf(Object);
var f = Function.prototype;

// All true:
console.log(a === f, b === f, c === f, d === f, e === f);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Everything in JavaScript inherits from Object.prototype. That is why everything in JavaScript is said to be objects. Even functions and arrays are objects under the hood.

So Object.prototype is the prototype of:

  • Function.Prototype
  • Array.Prototype

Function.Prototype is the prototype of Function and Array:

Array.prototype.prototype == Function.Prototype // true
Function.prototype.prototype == Function.Prototype // true

And again, Array and Function inherits from Object.prototype:

Object.getPrototypeOf(Array.prototype) == Object.prototype // true
Object.getPrototypeOf(Function.prototype) == Object.prototype // true

So to return to your question. The prototype of Object is Object.prototype. And Object.prototype is the prototype of Function.prototype, thus:

Object.getPrototypeOf(Object) == Function.prototype // true

JavaScript is like a family tree: Object.prototype had a baby called Function.prototype. Function.prototype then had babies of its own called Array and Function. And then follows arrays, classes etc... In the end, everything leads back to Object

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda