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

167
Visualizações
What is the equivalent of inheritance and extends keyword in JavaScript constructor functions?

I'm new to JavaScript and prototype-based programming. I know you can define inherited classes like class Circle extends Shape {}, but class is mostly a syntactic sugar of constructor functions, so is there any equivalent for inheritance of functions in JavaScript?

In other words, how can I define an inherited function without class keyword, like this:

var Shape = function() {
  this.getColor = function() {alert('Some color!')};
};

//Something like this:
var Circle = Function.create(Shape);

var circle1 = new Circle;

//With all below conditions:
console.log(Circle.__proto__ == Shape)                     // true
console.log(Circle.prototype.__proto__ == Shape.prototype) // true
console.log(circle1 instanceof Shape)                      // true
console.log(Object.getOwnPropertyNames(circle1))           // Array [ "getColor" ]

I've searched some articles but last condition wasn't achieved in them and getColor was an inherited property, rather than being a member of the circle1 itself.

about 4 years ago · Juan Pablo Isaza
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