Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda