Object Oriented JavaScript Tutorial #8 – Class Inheritance



Hey gang, in this object oriented JavaScript tutorial I’ll teach you about Class Inheritance.

🐱‍💻 Course Links:

– VS Code editor – https://code.visualstudio.com/
– GitHub repository (course files) – https://github.com/iamshaunjp/object-oriented-js
– JavaScript for Beginners – https://www.youtube.com/watch?v=qoSksQ4s_hg&list=PL4cUxeGkcC9i9Ae2D9Ee1RvylH38dKuET

🤑 Donate @ https://www.paypal.me/thenetninja

🎓Find me on Udemy @ https://www.udemy.com/user/47fd83f6-5e4a-4e87-a0f0-519ac51f91b6/

👾 Video thumbnail artwork by PixelSwish @ https://www.youtube.com/channel/UCGKSD3mitWl5UpMxZzaIrRA

Original source

23 thoughts on “Object Oriented JavaScript Tutorial #8 – Class Inheritance

  • January 17, 2019 at 01:48
    Permalink

    Inheritance does seem useful, but I have worries. What if, later on, you need to add properties to the user class that admin does not require?

  • January 17, 2019 at 01:48
    Permalink

    King Of Ninjas, Thanks For These Tuts They're Very Helpful, But I Hope You Make A Small Project Using Javascript ES6 OOP, Like OOP Shapes, Wisky Machine, etc … 🙂

  • January 17, 2019 at 01:48
    Permalink

    Hello , i was practicing after the video , i wanna know can i put the filter() function in separate function for example deletion() then call it in the deleteUser() function like that : users = users.filter(deletion);

  • January 17, 2019 at 01:48
    Permalink

    admin.deleteUser IS NOT A FUNCTION
    class User{

    // inside the class create a constructor to help us create object instances

    constructor(name, email, score){

    //set constructor properties

    this.name = name;

    this.email = email;

    this.score = 0;

    }

    //class methods are written outside the constructor but inside the class

    login(){

    console.log(this.email, 'Welcome …….loggedIn');

    return this;

    }

    logout(){

    console.log(this.email, 'Bye Now……..loggedOut');

    return this;

    }

    updateScore(){

    this.score++

    console.log(this.email, 'Score is Now', this.score);

    return this;

    }

    }

    class Admin extends User{

    deleteUser(user){

    users = users.filter(u => {

    return u.email != user.email

    });

    }

    }

    var userOne = new User('Nelson','nelson@gmail.com');

    var userTwo = new User('machoka','machoka@gmail.com');

    var userThree = new User('momo','momo@gmail.com');

    var admin = new User('mekenzi','mekenzi@gmail.com');

    //delete user

    var users = [userOne, userTwo, userThree];

    admin.deleteUser(userOne);

    console.log(users);

  • January 17, 2019 at 01:48
    Permalink

    Salut et merci 🙂

    Today, I have a little question:

    Why do we see [User, User, Admin] (class names) when we make a console.log (users) instead of [userOne, userTwo, admin] (the names of the variables)?
    The names of the variables no longer appear, even when we are doing 'users [0]' in the console.

    Thanks in advance

  • January 17, 2019 at 01:48
    Permalink

    Super helpful, thanks a ton Shaun! Being a newbie, I do have a general question about the code here. The deleteUser() method seems to only except the user as an argument instead of the user and users even though the method needs both to work. I'm assuming that's because the users array in global scope? Also, would there be any benefit/best practice to explicitly require the users array as an argument? e.g deleteUser(user, users)

  • January 17, 2019 at 01:48
    Permalink

    i would loved if you make "Real world projects" based tutorial on Udemy using JavaScript/Nodejs/ReactJs technologies 🙂

Leave a Reply