Allen Wirfs-Brock (2015-01-19T16:54:47.000Z)
d at domenic.me (2015-01-28T19:34:22.400Z)
On Jan 19, 2015, at 5:51 AM, Claude Pache wrote: > 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. At the JS level, I don't actually think about `new.target` as something that is "settable". I think about it as an oracle that tells me about how this function was invoked. null means it was invoked "as a function". non-null means it was invoked as a constructor and the value is the object that `new` was applied to. > 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 it isn't. Reflect.construct ensures that an non-null value is passed to [[Construct]] as its second argument > 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`. I originally intended `new.target` to use `undefined` is the sentinel value to indicated "called as a function". But as I wrote the spec. it felt better to use `null` in that role. I think it's because using `null` seems more special. `undefined` is used in so many places to indicated so many different things that it is hard to apply any generalized meaning to it. On the other hand, `null` is used in only a few places in the ES spec. so its use seems to draw attention to the specialness of those situations. But, I'd have no problem with changing back to `undefined` if there is a consensus in favor of that. It really makes very little difference as `null` and `undefined` are both falsey values, so the preferred way to write a "called as a function" these should probably be: ```js if (! new.target) ... ```
d at domenic.me (2015-01-28T19:34:12.854Z)
On Jan 19, 2015, at 5:51 AM, Claude Pache wrote: > 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. At the JS level, I don't actually think about `new.target` as something that is "settable". I think about it as an oracle that tells me about how this function was invoked. null means it was invoked "as a function". non-null means it was invoked as a constructor and the value is the object that `new` was applied to. > 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 it isn't. Reflect.construct ensures that an non-null value is passed to [[Construct]] as its second argument > 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`. I originally intended `new.target` to use `undefined` is the sentinel value to indicated "called as a function". But as I wrote the spec. it felt better to use `null` in that role. I think it's because using `null` seems more special. `undefined` is used in so many places to indicated so many different things that it is hard to apply any generalized meaning to it. On the other hand, `null` is used in only a few places in the ES spec. so its use seems to draw attention to the specialness of those situations. But, I'd have no problem with changing back to `undefined` if there is a consensus in favor of that. It really makes very little difference as `null` and `undefined` are both falsey values, so the preferred way to write a "called as a function" these should probably be: `if (! new.target) ...`