Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created November 19, 2019 14:23
Show Gist options
  • Select an option

  • Save codebubb/27d84db906417cfd3d0dcbd571bc557e to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/27d84db906417cfd3d0dcbd571bc557e to your computer and use it in GitHub Desktop.
Class Inheritance
class User {
constructor(name, password, loggedIn = false) {
this.username = name;
this._password = password;
this.loggedIn = loggedIn;
}
set password (pwd) { this._password = pwd };
get password () { return '*'.repeat(this._password.length); };
login() {
if (this.username === 'james' && this._password === 'Password123') {
this.loggedIn = true;
}
}
show() {
console.log(`Username: ${this.username}`);
console.log(`Password: ${this.password}`);
console.log(`Logged In: ${this.loggedIn}`);
}
static getLoginURL() {
return 'http://localhost/login';
}
}
class Developer extends User {
constructor(username, password, languages, loggedIn = false,) {
super(username, password, loggedIn);
this.languages = languages;
}
listLanguages() {
console.log(this.languages.join('\n'));
}
show() {
super.show();
this.listLanguages();
}
}
const james = new Developer('james', 'Password123', ['JavaScript', 'Ruby', 'Python']);
james.listLanguages();
james.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment