I have 2 very simple classes one is a parent class Calendar
the other the child class MonthCalendar
:
calendar.js:
import MonthCalendar from './month-calendar';
export default class Calendar {
constructor() {
this.date = new Date();
}
displayMonthCalendar(){
var mcal = new MonthCalendar();
mcal.generate();
}
}
var cal = new Calendar();
cal.displayMonthCalendar();
month-calendar.js:
import Calendar from './calendar';
export default class MonthCalendar extends Calendar {
constructor() {
super()
}
generate() {
alert('working');
}
}
When I try running this I keep getting the error:
Uncaught TypeError: Super expression must either be null or a function, not undefined
It's telling me Calendar
is undefined; however if I don't extend Calendar
and use it inside the generate()
method it is not undefined:
month-calendar.js:
import Calendar from './calendar';
export default class MonthCalendar {
generate() {
console.log(new Calendar());
}
}
That throws no error.