Reputation: 33
I'm extending the Date
class in a Typescript project. (Edit: I've simplified this code slightly into a more barebones version)
class ExtendedDate extends Date {
get fullYear() {
return this.getFullYear();
}
}
export class DateTest extends Scene {
constructor() {
super();
let tDate = new ExtendedDate();
console.log(tDate);
console.log(tDate.fullYear);
console.log('Is extended date: ' + (tDate instanceof ExtendedDate));
}
}
On my computer, as expected, the console shows the current date followed by the year and Is extended date: true
. But on some machines in Chrome, it still shows the date but tDate.fullYear
is undefined
and it says Is extended date: false
. So instead of using my extended class, it seems to have created a regular Date object.
This seems to be brand-new behaviour: the same code was working on all browsers until two days ago, and is still working fine in Edge. Has there been some change to Chrome that makes this fail? And is this because I'm doing something I shouldn't?
EDIT: In response to the question below, "What is the actual JavaScript code emitted by the TypeScript compiler", I had to fight webpack a bit because it was using eval-source-map, but what I ended up with was more or less identical to the original code:
class ExtendedDate extends Date {
get fullYear() {
return this.getFullYear();
}
}
class DateTest extends _Scene__WEBPACK_IMPORTED_MODULE_0__.Scene {
constructor() {
super();
let tDate = new ExtendedDate();
console.log(tDate);
console.log(tDate.fullYear);
console.log("Is extended date: " + (tDate instanceof ExtendedDate));
}
}
The questioner also asked "Is it the same JavaScript code in all environments", and if I understand the question correctly the answer is yes, since it's just running plain JavaScript on a web page, without any dynamic code.
For further clarity: both the test machines (mine where it works correctly and my boss's where it's failing) are running Windows 10 and Chrome 114.0.5735.134
Upvotes: 0
Views: 39