Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re: "Class scoped lexical function declarations" #16

Open
matthewrobb opened this issue Mar 8, 2017 · 1 comment
Open

re: "Class scoped lexical function declarations" #16

matthewrobb opened this issue Mar 8, 2017 · 1 comment

Comments

@matthewrobb
Copy link

Class scoped lexical function declarations

If my mind is correctly understanding this I would just like to express that I think this is a wonderful idea.

It also brought to mind the idea of instance-bound methods which currently if using a transpiler like babel you would express like this:

class Foo {
  bar = ()=> {}
}

But this has limitations for example I don't believe you can perform super calls from within them. It may have been suggested before but it seems as though an easy win improvement could be:

class Foo {
  bar()=> {}
}

The only syntactic difference in my mind would be strictly enforcing the use of parens but I could also see a valid argument for strictly enforcing a block body.

@allenwb
Copy link
Contributor

allenwb commented Mar 20, 2017

what we have in mind is using actual lexical declarations within the nested class scope:

class Foo {
   function bar() {};  //a function declaration, lexically scope to class body.
   const k = 42;          //a const lexically scoped to class body
   const sum = (a,b) => a+b;
   let count = 0;    //a variable scoped to the class body
   class FooHelper {
      own a,b;
      constructor(a) {
          count++;
          this.a=a;
       }
   }
   own #x = new FooHelp(1);  //private field initialized to lexically protected helper class
}

Note that the bindings created by such lexical declarations are not fields or properties of any of the constructor, prototype, or instance objects associated with the class declaration. They are ordinary lexical bindings whose scope is the class body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants