Class double-bind

Jason Orendorff jason.orendorff at gmail.com
Mon Mar 2 21:07:43 UTC 2015


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


More information about the es-discuss mailing list