Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active December 22, 2020 17:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericelliott/0580e15d9cbfe294556c1e75b79d8093 to your computer and use it in GitHub Desktop.
Save ericelliott/0580e15d9cbfe294556c1e75b79d8093 to your computer and use it in GitHub Desktop.
Class inheritance demo (not recommended)
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