Suppose I define a variable like this
var today = Date();
console.log(today.getMonth()); // Throw Error
while other class like Error class call their methods without new operator.
function factorial(x) {
if(x <= 1)
throw Error("x must not be negative");
return x*factorial(x-1);
}
Also wrapper objects (number, boolean, string) can call their methods without new operator. So, Is this the only class which require new operator or any object creation technique before calling their methods.
Edit: As Date() is a string type, so it should be call their methods without creating objects. Because string type behave as if they are objects. So why not?
Edit 2: I think this is the only core function which cannot be same as new Date()
like other functions (Array(), String(), Error()
etc). So, it's also the hidden feature of this language or ECMAScript mistake.