I create this class:
class trueDate extends Date {
constructor(date: string) {
super(date)
}
getDay(): number {
var day = super.getDay()
return day === 0 ? 7 : day
}
addDate(date: number) {
super.setTime(super.getTime() + date * 86400)
}
}
But, when I call methods on an inherited class (for example: trueDateObj.getDate()) get the error:
Uncaught TypeError: this is not a Date object.
Output JS code:
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var trueDate = (function (_super) {
__extends(trueDate, _super);
function trueDate(date) {
_super.call(this, date);
}
trueDate.prototype.getDay = function () {
var day = _super.prototype.getDay.call(this);
return day === 0 ? 7 : day;
};
trueDate.prototype.addDate = function (date) {
_super.prototype.setTime.call(this, _super.prototype.getTime.call(this) + date * 86400);
};
return trueDate;
})(Date);
I create new object like this:
var trueDateObj = new trueDate("date-string")
Firefox error:
TypeError: getDate method called on incompatible Object