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

Поділитися
Вставка
  • Опубліковано 1 чер 2018
  • 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:
    developer.mozilla.org/en-US/d...
    Support me on Patreon:
    / dcode
    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!

КОМЕНТАРІ • 34

  • @ymarchitect
    @ymarchitect 2 роки тому +7

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

  • @kiritosenpai8082
    @kiritosenpai8082 2 роки тому

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

  • @youngmeeshin2452
    @youngmeeshin2452 3 роки тому +3

    Always. Simple clear. Love your teachings

  • @erickoavenada969
    @erickoavenada969 5 місяців тому

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

  • @dopetag
    @dopetag 2 роки тому

    Wow! Amazing explanation and examples. Thank you!

  • @mekanarazmedov1786
    @mekanarazmedov1786 5 років тому +1

    Great explanation, thank for this video.

  • @HumAnTarg3t
    @HumAnTarg3t 3 роки тому

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

  • @LetsGeTDeep
    @LetsGeTDeep 2 роки тому

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

  • @kiritosenpai8082
    @kiritosenpai8082 2 роки тому

    Great explication,Thanks very much!

  • @zsofiaszabo6687
    @zsofiaszabo6687 3 роки тому +1

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

  • @elviradark6902
    @elviradark6902 2 роки тому

    Thank you for the clear explanation.

  • @stevonarksem3477
    @stevonarksem3477 4 роки тому

    you are really teach thanks so much

  • @manikantajupudi4129
    @manikantajupudi4129 2 роки тому

    Thanks, Sir.

  • @eth-official
    @eth-official 2 роки тому

    thank you man

  • @ygge2007
    @ygge2007 2 роки тому +1

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

  • @cannabisanomaly
    @cannabisanomaly Рік тому

    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!

  • @VishnuSunilkumar
    @VishnuSunilkumar 3 роки тому

    I love your wpm. Loved listening to your keys.
    BTW Thanks for making this video.

  • @yamacode9958
    @yamacode9958 6 років тому +3

    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.

    • @dcode-software
      @dcode-software  6 років тому +1

      Hey there, calling "super(_name, _age)" will call the parent constructor, meaning whatever code is in the parent constructor will be executed for the context of the child class

  • @mdabdullah-dg4xs
    @mdabdullah-dg4xs Рік тому

    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?

  • @yamacode9958
    @yamacode9958 6 років тому +2

    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?

    • @dcode-software
      @dcode-software  6 років тому

      Yeah that's right, you can only call the method on an instance of a class where it exists

  • @yamacode9958
    @yamacode9958 6 років тому +1

    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?

    • @dcode-software
      @dcode-software  6 років тому

      When you call a constructor you'll get an instance of the class. So inside the array you are calling two constructors so you'll have two instances of that class inside the array.
      This could be another way of achieving the same result:
      const P1 = new Programmer("Dom", 54, 12);
      const P2 = new Programmer("Jeff", 24, 4);
      const programmers = [P1, P2];

    • @yamacode9958
      @yamacode9958 6 років тому +1

      In your comment example they are called p1 and p2, but in the video they referenced as programmers[0] and programmers[1] is this correct?

    • @dcode-software
      @dcode-software  6 років тому

      I was just showing you another way to achieve the same result :) you can then reference the two Programmer instances by using programmers[0] and programmers[1]

    • @mekanarazmedov1786
      @mekanarazmedov1786 5 років тому

      pazira love, I think it wouldn't be correct to say he "calls class" from inside of array. What does call class really mean anyway? He creates new instances of Programmer class and stores them in an array called programmers. And in the last part, our function uses this array, it loops through it and makes them work ))

  • @gowthams8340
    @gowthams8340 6 років тому +2

    Is this Js Es6 Or normal Js?

    • @dcode-software
      @dcode-software  6 років тому

      Hey there mate, this class syntax was released with ES6 😁

    • @gowthams8340
      @gowthams8340 6 років тому +1

      dcode I'm begginer so little bit confused anyway thanks

  • @akbarangkasa6571
    @akbarangkasa6571 Рік тому

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

  • @contactmerrou
    @contactmerrou 3 роки тому +1

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

  • @_.sunnyraj._
    @_.sunnyraj._ 3 роки тому

    Are u 56?