¡GoConqr estrena diseño! Cuéntanos qué te parece.

Módulo 9 de 14 · Multimedia

Extends

Kostas Diakogiannis

Extends

Object inheritance

Through the class syntax is very easy to create an hierarchy, a chain and create objects that don't hold necessarily their own properties and methods but they inherit from other classes. This is a core concept of object oriented programming and it's not specific to JS. 

We can save a lot of typing by defining classes that hold properties and methods and then pass these methods (or bequeath if you like) to other classes or objects!. 

In order for a class to inherit properties of another class we use the extends keyword on the child class. Then inside the child's class constructor function we use the super function, which is equivalent to the new keyword. Is a reference to the constructor function of the class we inherit from.

 

If you  at the example above, the jake object has all the properties of the Person constructor, those are it's OWN properties and a property 'nationality', which is bequeathed from the Greek class to the Person class through the super() function and the extends keyword that the Person class uses to reference any 'parent' classes and inherit from them.

Already confused?let's make an exercise and see inheritance in full strength!

Instrucciones

Para avanzar en el curso, envía un intento de este test. Puedes enviarlo después de la última pregunta.

Ir al módulo elegido

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?