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

134
Visualizações
Why JavaScript construction function default prototype is Object.Prototype instead of Function.prototype?

When function object is used as constructor then proper prototype chain is maintained as marked in point 1 and point 2.

But as shown in following code new instances prototypes are skipping Function.prototype and directly inheriting from Object.prototype. Is there specific reason for that?

Function.prototype.extraFun = function(){console.log('funny function')};

function Thing(name){
    this.name = name;
}

Thing.prototype.specs = function(){
    return `name: ${this.name}`;
}

var table = new Thing('wooden table');

table.__proto__ == Thing.prototype //true       [OK]            (1)
Thing.__proto__ == Function.prototype //true    [OK]            (2)  

//it should show follow the above rythm
Function.__proto__ == Object.prototype //false               (A)

//why 
Function.__proto__ == Object.__proto__ //true                (B)

//it should be false
table.__proto__.__proto__ == Object.prototype // true             (3)  

//it should be true because function object is instance of Function NOT Object directly
table.__proto__.__proto__ == Function.prototype //false            (4)

But issue is why point 3 is true and point 4 is false. Further more Point A and B are deviate from normal order unlike point 1 and 2

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

table.__proto__ == Thing.prototype //true       [OK]            (1)
Thing.__proto__ == Function.prototype //true    [OK]            (2)  

//it should show follow the above rythm
Function.__proto__ == Object.prototype //false               (A)

//why 
Function.__proto__ == Object.__proto__ //true                (B)

Not really. table is the odd one out. The rythm goes like this:

Thing.__proto__ == Function.prototype //true    [OK]
Function.__proto__ == Function.prototype //true [OK]
Object.__proto__ == Function.prototype //true   [OK]

Can you see what these have in common? They're constructor functions.

table.__proto__ == Thing.prototype //true       [OK]            (1)
Thing.__proto__ == Function.prototype //true    [OK]            (2) 
table.__proto__.__proto__ == Object.prototype // should be false but is true?
table.__proto__.__proto__ == Function.prototype // should be true but is false?

No, there is no function object (that would be an instance of Function, and inherit from Function.prototype) involved in the prototype chain of table. You seem to be thinking that Thing.prototype and Thing.__proto__ are the same thing - but no, they're absolutely not.

The inheritance chain simply goes

           table.__proto__ == Thing.prototype
 Thing.prototype.__proto__ == Object.prototype
Object.prototype.__proto__ == null
about 4 years ago · Juan Pablo Isaza Relatório

0

Constructors (Thing, Function, Object) are functions, so they have Function.prototype in their prototype chain.

Function.prototype and Thing.prototype inherit from Object.prototype:

enter image description here

The lines represent .__proto__ dependencies (upwards).

See How does JavaScript prototype work?, where I also posted an answer.

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