Created
November 19, 2019 14:23
-
-
Save codebubb/27d84db906417cfd3d0dcbd571bc557e to your computer and use it in GitHub Desktop.
Class Inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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