I\'m trying to subclass/extend the native Date object, without modifying the native object itself.
I\'ve tried this:
var util = require(\'util\')
Section 15.9.5 of the EcmaScript spec says:
In following descriptions of functions that are properties of the Date prototype object, the phrase 'this Date object' refers to the object that is the this value for the invocation of the function. Unless explicitly noted otherwise, none of these functions are generic; a
TypeErrorexception is thrown if the this value is not an object for which the value of the[[Class]]internal property is"Date". Also, the phrase 'this time value' refers to the Number value for the time represented by this Date object, that is, the value of the[[PrimitiveValue]]internal property of this Date object.
Note specifically the bit that says "none of these functions are generic" which, unlike for String or Array, means that the methods cannot be applied to non-Dates.
Whether something is a Date depends on whether its [[Class]] is "Date". For your subclass the [[Class]] is "Object".