0

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

  • If that's the JS code and it's the same in both environments, then I'm afraid I have no idea how it could be failing. I think you might need to step through the code with a debugger, from your boss's haunted computer. At the very least we will need to hear more about the differences between the two environments, because right now this just looks like an irreproducible issue and thus the question might end up being closed as needing debugging details. I'll probably disengage now; maybe others will have some insight? Good luck! – jcalz Jun 22 '23 at 14:19
  • Appreciate your help anyway. For what it's worth, this isn't just happening on his computer, we've had reports of what sounds like the same issue on more than one client machine as well. But I'm glad to hear it's not just me doing something stupid, anyway. – Danny Kodicek Jun 22 '23 at 15:11

0 Answers0