Let's say that we have the following code...
class Person {
sayHello() {
console.log('hello');
}
walk() {
console.log('I am walking!');
}
}
class Student extends Person {
sayGoodBye() {
console.log('goodBye');
}
sayHello() {
console.log('hi, I am a student');
}
}
var student1 = new Student();
student1.sayHello();
student1.walk();
student1.sayGoodBye();
// check inheritance
console.log(student1 instanceof Person); // true
console.log(student1 instanceof Student); // true
That works well... but now let's say that the Student class doesn't extend Person at it's declaration class Student extends Person {
becomes class Student {
.
Now we have class Person
and class Student
.
Is there a way to have Student
extend Person
without having the extends
in the class declaration?
EDIT: [more detail]
The reason I'm using this pattern is because I'd like to use Mongoose's extends Model
but I'm creating the Model objects in a node_module rather than in the back-end API. This is so that I can use shared classes for the front and back-end reducing redundant code. I obviously can't use mongoose in the front-end so I'm only going to be extending that functionality in the back-end.