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 responses to “Object Oriented JavaScript Tutorial #8 – Class Inheritance”

  1. 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);

  2. 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);

  3. 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

  4. 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)

Leave a Reply