A new ES6 draft is available
claude.pache at gmail.com
Mon Jan 19 05:51:42 PST 2015
> Le 19 janv. 2015 à 11:58, Andreas Rossberg <rossberg at google.com> a écrit :
> On 17 January 2015 at 19:14, Allen Wirfs-Brock <allen at wirfs-brock.com <mailto:allen at wirfs-brock.com>> wrote:
> On Jan 17, 2015, at 9:53 AM, Domenic Denicola wrote:
> > On Jan 17, 2015, at 12:31, Allen Wirfs-Brock <allen at wirfs-brock.com <mailto:allen at wirfs-brock.com>> wrote:
> >> If the enclosing function is invoked as a call expression the value of `new.target` is null
> > Just curious, why null instead of undefined?
> null is used to indicate no [[Prototype]], so it seem to me to be a better match for this situation.
> Wouldn't the fact that null is a quasi-legal prototype strongly speak for using undefined here? Otherwise, it seems you couldn't distinguish Call invocations from Construct invocations with a prototype that has actually been set to null (which I suppose is legal?).
> (In terms of proper option/maybe types, this is yet another case of a None vs Some(None) distinction.)
`new.target` is a reference to the constructor, not the prototype, so the problem does not arise in practice.
But anyhow, I do think that `undefined` is semantically better here:
* `new.target === null` means: `new.target` has been set to "no object".
* `new.target === undefined` means: `new.target` has not been set.
When you execute a function body with the semantics of [[Construct]], the value of `new.target` is the original constructor on which `new` was applied. If it was possible to have the semantics of [[Construct]] with no original constructor, then `new.target` would be `null` (no-object).
But when you execute a function body with the semantics of [[Call]], there is no notion of "original constructor", and `new.target` is left with no value, i.e. `undefined`.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss