Last active
December 22, 2020 17:07
-
-
Save ericelliott/0580e15d9cbfe294556c1e75b79d8093 to your computer and use it in GitHub Desktop.
Class inheritance demo (not recommended)
This file contains 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 = 'Anonymous' }) { | |
this.name = name; | |
} | |
login () { | |
console.log(`${ this.name } logged in.`); | |
} | |
}; | |
class Student extends User { | |
constructor (options) { | |
super(options); | |
this.completedLessons = []; | |
} | |
completeLesson (id) { | |
this.completedLessons.push(id); | |
console.log(`${ this.name } completed lesson: ${ id }`); | |
} | |
} | |
const echo = new Student({ | |
name: 'Echo' | |
}); | |
echo.login(); // "Echo logged in." | |
echo.completeLesson(1); // "Echo completed lesson: 1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment