Suppose I define such a variable
var today = Date(); console.log(today.getMonth());
while another class, such as the Error class, calls their methods without a new statement.
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 a new operator. So, this is the only class that requires a new operator or any technique for creating objects before calling its methods.
Edit: Since Date () is a string type, it should call their methods without creating objects. Because the string type behaves as if they were objects. So why not?
Change 2 . I think this is the only key function that cannot be the same as new Date() like other functions ( Array(), String(), Error() , etc.). Therefore, it is also a hidden function of this language or an ECMAScript error.
source share