0

In my app.js (my main file), I want to override getTime();

So now, when I call created_at.getTime() in all of my node.js failes that stem from app.js via requires, they should use this new getTime() function that I just overrided.

Basically, I want to change the entire getTime() function to my own, throughout my entire project.

UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

1

You can override Date.prototype.getTime but DO NOT DO THAT as it will break many libraries you would ever use.

You can use the same trick as with JSON.parse:

var serialized = JSON.stringify(obj, function (key, value) {
    if (value instanceof Date) {
      return dateHandler(value);
    } else {
      return value;
    }
});

You would define the dateHandler function.

To keep others in the loop, I'm referring to OP's previous question.

Community
  • 1
  • 1
J. K.
  • 8,268
  • 1
  • 36
  • 35