I can call parse method of Date object directly as follows:
alert(Date.parse("March 21, 2012"));
However I cannot do this:
alert(Date.getTime()); // TypeError: Date.getTime is not a function
That is how I get it working:
alert(new Date().getTime()); // works well
So why can’t I call Date.getTime() directly like Date.parse()?
Underlying Question: I have written a class and I want to use some of its methods directly like Date.parse() above.
As others have pointed out, JavaScript uses prototypes to defined instance methods. You can however defined static methods as shown below. I am not trying to define the whole
Dateobject here, but rather show how its instance and static functions are defined.