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

159
Vistas
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 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