Class double-bind

Erik Arvidsson erik.arvidsson at gmail.com
Mon Mar 2 21:35:03 UTC 2015


Classes are more similar to function expressions which do have an internal
const binding.

One way to desugar ClassDeclaration is to desugar it into a let binding for
a ClassExpression. [1]

let Foo = class Foo extends expr {};

I would prefer if we didn't change the spec, not because I think it is too
late (it is) but because having an internal const binding is good because
then you can rely on that it will never change.

[1] This is actually what we do in V8.

On Mon, Mar 2, 2015 at 10:12 PM Mark S. Miller <erights at google.com> wrote:

> All else being equal, your suggestion seems like the obviously right
> thing, on at least consistency and least surprise grounds.
>
> I know we discussed this. Anyone remember why we didn't do what Jason
> suggests? My memory of counter-arguments here is blank.
>
>
>
>
> On Mon, Mar 2, 2015 at 1:07 PM, Jason Orendorff <jason.orendorff at gmail.com
> > wrote:
>
>> Classes are specified to have an immutable inner binding even if they
>> also declare a mutable lexical binding in the enclosing scope:
>>
>>     class Foo {
>>         foo() {
>>             // immutable inner binding 'Foo' is in scope here
>>         }
>>     }
>>     // mutable lexical binding 'Foo' is in scope here
>>
>> Having two bindings can be tricky. Suppose I then do this:
>>
>>     Foo = wrapConstructorWithExtraLogging(Foo);
>>
>> Now the two bindings have different values. If one of Foo's methods
>> does `new Foo`, we don't get the extra logging.
>>
>> Can we go back to having classes do what functions do? A single
>> function never introduces two bindings; rather a named function
>> expression has only the immutable inner binding and a function
>> declaration only declares a variable.
>>
>> -j
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
>
> --
>     Cheers,
>     --MarkM
>  _______________________________________________
> 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/20150302/6c97678e/attachment.html>


More information about the es-discuss mailing list