Hello I'm wondering how to extends a constructor like Date, The thing is I have a large, very large application and I want to know each time a Date object is instanciated. Basically I want to print something in the constructor. I don't want to define a new construtor in which I would call Date() and then replace Date by the new constructor all over the code. I really want to extend Date. And I came up with this:
var previousPrototype = Date.prototype;
Date = function() {
previousPrototype.constructor.call(this);
console.log('new Date instanciation');
}
Date.prototype = previousPrototype;
var extendedDate = new Date(); // prints 'new Date instanciation'
that seems good, but when I do extendedDate.getTime()
for instance I get that sweet message
VM103:1 Uncaught TypeError: this is not a Date object.
I don't understand why it's not working, any help will be appreciated