Doubts with EcmaScript 6 exercise

This ECMAScript exercise talks about creating two classes, one of user (where email and password entry will occur), another of Administrator (where in addition to email and password entry, it talks about whether it is adm.

Why does the input method isAdmin() stay in the User class and not the administrator? I mean, if it's to verify that the class is an administrator, wouldn't it be better to stay in the administrator class?

The code in question is is:

class Usuario{
    constructor(email, senha){
        this.email = email;
        this.senha = senha;
    }
    isAdmin(){
        return this.admin === true;
    }
}

class Admin extends Usuario{
    constructor(email, senha){
        super(email, senha);

        this.admin = true;
    }
}

const User1 = new Usuario("[email protected]", "senha123");
const Adm1 = new Admin("[email protected]", "senha123");

console.log(User1.isAdmin()); //retornará false
console.log(Adm1.isAdmin());  //retornará true
Author: Bacco, 2020-10-08

1 answers

Is that the Admin class inherits the methods and attributes of the User class, so extends it. Think that an admin is a user, and it needs to check if the user is an Admin, and not if an Admin is an Admin. I hope I helped!

 -1
Author: João Fernando Garcia de Souza, 2020-10-08 16:32:57