Christopher said:
I would like to subclass the built-in Date object to get additional
functionality out of it, but the code below gives me an error
something like "object is not a date object". Is there something I'mm
doing wrong?
function foo() {
}
foo.prototype=new Date();
alert( new foo().getHours() );
The ECMAScript specification says clearly:
15.9.5 Properties of the Date Prototype Object
The Date prototype object is itself a Date object (its [[Class]] is
"Date") whose value is NaN.
The value of the internal [[Prototype]] property of the Date prototype
object is the Object prototype
object (15.2.3.1).
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. None of these
functions are generic; a TypeError exception is thrown if the this value
is not an object for which the
value of the internal [[Class]] property is "Date".
so an implementation is supposed to throw an error if you try to call a
method like getHours on an object that is not a Date object.
Perhaps it suffices for you if you extend Date e.g.
Date.prototype.yourMethod = function (...) { ... };