That's good to know and it's good to know I'm not the first one to spot
this.

While we're visiting the spec on that:

Why is it specified that "When called as a constructor it creates a new
ordinary object. When Object is called as a function rather than as a
constructor, it performs a type conversion." - wouldn't it make more sense
to remove that or specify "behaves the same way"?

Where is it actually explained what Object does when called as a
constructor?

The difference - at least in the phrasing of Object vs Array seems to be
just as present in the latest spec draft from what I can tell.



On Sat, Jun 13, 2015 at 12:38 AM, Allen Wirfs-Brock <al...@wirfs-brock.com>
wrote:

> 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@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to