When playing with built-in objects and JavaScript constructors, I noticed something a bit strange.
Sometimes you can get new objects by calling the constructor without new . For instance:
> new Array(1,2,3,4) [1, 2, 3, 4] > Array(1,2,3,4) [1, 2, 3, 4]
But sometimes this does not work:
> Date() "Thu Jun 05 2014 00:28:10 GMT-0600 (CST)" > new Date() Date 2014-06-05T06:28:10.876Z
Is the behavior of inline functions of a non-new constructor defined in the ECMAScript specification? Please note that this behavior is really useful; I can make an unsharp copy of the array by calling Array.apply(arr) , but I would feel comfortable if it were cross-platform.
source share