Edit: this question is different from How to extend a class without having to using super in ES6? - although the answers are related, this is very obviously a different question. It relates to a specific error, and the two main classes involved Person
and CreationEvent
don't actually inherit from each other.
I have two ES6 classes, Person
and CreationEvent
(CreationEvent
inherits from Event
). I wish to to make a new CreationEvent
when I make a new Person
(as the CreationEvent
is part of the events in the history of person's account).
Running new CreationEvent()
on it's own works fine. However I can't run new Person()
.
Even with reduced version of the code still fails:
class Event {
constructor() {
this.time = Date.now()
this.tags = []
}
}
class CreationEvent extends Event {
constructor() {
this.description = "Created"
}
}
class Person {
constructor(givenName, familyName, email) {
var creationEvent = new CreationEvent()
}
}
Running new Person()
returns
ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
How do I make a new ES6 Object in another Object's constructor?