JavaScript Classes #4: Inheritance & Extends - JavaScript OOP Tutorial

preview_player
Показать описание
By using the "extends" keyword with your JavaScript classes you are able to create inheritance which is where you have a child class that inherits the instance properties and methods of its parent class.

You'd typically use a feature like this on the server-side with NodeJS as this can be considered to be a complex design - although classes can be used to represent similar visual components on the front-end.

In this video I take you through a simple example of how you can make use of the extends keyword to achieve inheritance - you'll see how we create a "child" version of a Person class, a Programmer. programmer has all the features of a person but with a little but extra!

For your reference, check this out:

Support me on Patreon:

Follow me on Twitter @dcode!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

Your way not to hide occasional typing mistakes and executin errors is the better teaching method than showing perfect procedures. I like the way.

ymarchitect
Автор

Always. Simple clear. Love your teachings

YoungmeePark
Автор

Great explanations, from the start i understand what i didnt understood before

erickoavenada
Автор

mesmo sem entender o que ele estava dizendo, suas separações e jeito de fazer me deram uma luz, obrigado!!!

kiritosenpai
Автор

Hiya mate, don't mind me just saying how much I love this series again lol

LetsGeTDeep
Автор

thanks, was really confused about the super method, think i got it now!

HumAnTargt
Автор

Wow! Amazing explanation and examples. Thank you!

dopetag
Автор

Great explanation, thank for this video.

mekanarazmedov
Автор

Hi Dom, thank you for this tutorial. I'm wondering if "extends" is somehow similar to Object.prototype?

ygge
Автор

Thank you, it was a really helpful video! :)

zsofiaszabo
Автор

Thank you very much for the informative video! You have a knack for teaching. I had one question though; when you form the class's instance properties:

class Person {
constructor(_name, _age) {
this.name = _name;
this.age = _age;
}

Would the correct syntax to indicate a private property be this instead?

class Person {
constructor(name, age) {
this._name = name;
this._age = age;
}

Since that way, once the actual object instance is seen with the property name, it becomes more apparent that it's a private property?

Really small detail, but just wasn't sure what the so-called "standard" should be. Thank you again for a great video!

cannabisanomaly
Автор

Does super(_name, _age) being the name and age properties to the new child class. Am I right in my understanding that once you have used super(_name, _age) you save time by not writing those properties yourself and just "extend" it from another class?. If the parent class does not have a property you need, you can add it yourself like you did with yearsOfExperience.

yamacode
Автор

I also have other question, sorry for taking your time. The only way to access the property or method of a child class is by using its own name and not its parents. Is this correct?

yamacode
Автор

I love your wpm. Loved listening to your keys.

BTW Thanks for making this video.

VishnuSunilkumar
Автор

I also have another question for you, sorry for taking your time. can we inherit multiple parent classes in our one child class?
If it can be done, how do I do it?

mdabdullah-dgxs
Автор

I dont understand this too
const programmers = [
new Programmer("Dom", 54, 12),
new Programmer('Jeff', 24, 4)

] I know its an array but how do you call a class from inside an array, how does this code work?

yamacode
Автор

when you realise a 10 minutes youtube video nowadays worth more than a whole semester of your college smh.. 😤

akbarangkasa
Автор

Nice video, thanks! Though, please use some girls' names for your examples. Not only men code ;)

contactmerrou
join shbcf.ru