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

151
Visualizações
Prototype of class's instances?

I'm trying to understand why the following code works the way it does.

I think it's contradictory that logging killerRabbit.prototype gives undefined while at the same time it seems to be equal to Rabbit.prototype.

Does it has an associated prototype but no actual prototype as a property?.

In that case, how do I access those prototypes properties?

class Rabbit {
  constructor(type) {
    this.type = type;
  }
  speak(line) {
    console.log(`The ${this.type} rabbit says '${line}'`);
  }
}
let killerRabbit = new Rabbit("killer");
console.log(Object.getPrototypeOf(killerRabbit)==Rabbit.prototype);//true
console.log(killerRabbit.prototype);//undefined
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to access the prototype property on an instance, try this:

console.log(killerRabbit.__proto__);

And this property point to the prototype property of the based class.

console.log(killerRabbit.__proto__ === Rabbit.prototype); // true
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