Wanting to create a custom Date
subclass with an overridden constructor:
export class MyDate extends Date {
constructor(str: string) {
super(str);
}
}
However, when attempting to instantiate a MyDate
object, it fails :
var myDate = new MyDate("2016-10-20T12:30:00+0200");
console.log(myDate.toDateString()); // throws an error, myDate is incorrect
An error message displays:
TypeError: Method Date.prototype.toDateString called on incompatible receiver [object Object]
.
Seeking a solution to override the Date
constructor. Is this achievable?