`new Object` vs `Object` difference

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Jun 12 21:38:48 UTC 2015


ES6 eliminates the (possible) special treatment of host objects passed as the argument to the Object constructor. As far as anybody seems to know, no implementation had ever made use of that allowance. 

The ES6 spec. also unifies the [[Call]] and [[Constructor]] behavior of Object into a single algorithm http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object-value 
ES6  unifies all  [[Call]] and [[Construct]] algorithms for built-in constructors in this same manner.

Allen







On Jun 12, 2015, at 1:19 PM, Benjamin Gruenaum wrote:

> Ok, so I gave this a few hours in the open.
> 
> So, I'm looking at the ES5 specification (also checked the current ES draft which is similar) at the definition of what new Object and Object do. To my surprise:
> 
> - `new Object` describes a whole algorithm of how the object constructor works - treating what happens with different kinds of values. Basically calls `ToObject` on non objects - identity on objects and builds on null and undefined.
>  - `Object` has a special first step for null and undefined where it builds an object and then calls `ToObject` on primitives and identity on objects.
> 
> After reading the description a few times - they seem identical. However, clearly from the spec they do *something* different. For example in Array - calling new Array is specified as the function call Array(…) is equivalent to the object creation expression new Array(…) with the same arguments.`
> 
> The only difference I've been able to identify with the help of a friend is that the behaviour can be different on host objects. Where `Object` must return the same host object and `new Object` _may_ return the same host object.
> 
> I've taken a look at the ES3 specification and it too uses the same definition so I suspect this is something that has been there for a long time.
> 
>  - Why are `Object` and `new Object` specified differently?
>  - If there is no actual reason, can the definition be simplified for the next version of the spec? (I think simplifying the spec is important and possibly underrated) 
> 
> Sorry if I'm missing something obvious.
> 
> Originally asked on Stack Overflow - http://stackoverflow.com/q/30801497/1348195
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150612/8d8d680a/attachment.html>


More information about the es-discuss mailing list