es-discuss Digest, Vol 95, Issue 45
Isiah Meadows
impinball at gmail.com
Sun Jan 18 18:06:53 PST 2015
> From: Allen Wirfs-Brock <allen at wirfs-brock.com>
> To: "Fabrício Matté" <ultcombo at gmail.com>
> Cc: es-discuss <es-discuss at mozilla.org>
> Date: Sat, 17 Jan 2015 12:14:17 -0800
> Subject: Re: A new ES6 draft is available
>
> On Jan 17, 2015, at 11:57 AM, Fabrício Matté wrote:
>
>> > Currently in ES6, the only reserved keywords that can appear
immediately before a `.` are `this` and `super`.
>>
>> The `this` binding resolves to a value, so MemberExpressions make sense.
The `super` keyword is being implemented in ES6, so there are no precedents
to set expectations.
>>
>> > Any other reserved word followed by a `.` is a syntax error. So
reserved words followed by period and an identifier is one of the few
available extension alternatives we have available. And is a natural ready
syntax think of new.target' as meaning give me the target value of the
currently active `new` operator.
>>
>> I agree `new.target` is very natural and pleasant to read. It just feels
rather alien to see an operator in the beginning of a MemberExpression,
which currently would only be allowed in this very specific scenario. Of
course, if this syntax extension form would be useful for other use cases
as Kevin and you have outlined, then I don't oppose it.
>>
>> > I suspect the hypothetical naive JS programmer postulated above
wound't be aware of any of those concepts.
>>
>> A naive one probably not, but a curious avid developer most definitely
would. ;)
>>
>> > hopefully they will say what is `new.target', "google it" and
immediately find the answer.
>>
>> You mean, land on a Stack Overflow answer with thousands of upvotes and
very little explanation about why/how a MemberExpression can begin with an
operator. Of course, if you interpret `new` as simply a ReservedWord token
instead of an operator, then everything makes perfect sense.
>
>
>
> The way I accomplish in the grammar was to add the productions:
>
> MemberExpression :
> MetaProperty
> MetaProperty :
> 'new' '.' 'target'
>
> So we could start talking about "meta properties" as a MemberExpression
alternative and say `new.target` is a "meta property".
>
> Allen
Is my understanding correct in that these two conditions are effectively
equivalent?
```js
class Foo {
constructor() {
if (new.target === null)
return new Foo();
console.log(new.target === Foo);
}
}
var global = Function('this')();
function Bar() {
if (this === global)
return new Bar();
console.log(this.constructor === Bar);
}
```
If so, then it would be an easy string transform to write, considering its
small scope. (delimited by any operator except period on each side, keep
parentheses balanced, done in one pass, potentially in a buffer - could
even be in hand-written asm.js, great for node)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150118/b3f6db35/attachment-0001.html>
More information about the es-discuss
mailing list