Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save WebReflection/a9e56cd54fbcfdb15bff to your computer and use it in GitHub Desktop.

Select an option

Save WebReflection/a9e56cd54fbcfdb15bff to your computer and use it in GitHub Desktop.
Annotated static group in class definition

The proposal is to be able to define multiple static properties as group, using already defined object literal syntax.

// currently in ES6
class Foo {
  static f() {return 'f';}
  static get g() {return 'g';}
}


// proposed for ES7
class Foo {
  static {
    f() {return 'f';},
    get g() {return 'g';}
  }
}

Using an object might bring also the ability to define constant like properties without needing to use a getter per each of them.

class Foo {
  static {
    a: 'a',
    f() {return 'f';},
    get g() {return 'g';}
  }
}

Configurability, writability, and enumerability of property a should be exactly the same of any other statically defined property.

Goals

  • more compact and cleaner class definition, statics are defined in one place instead of potentially everywhere down the class definition
  • less ambiguity for the this reference, the static reference is for the current class and not its prototype.
  • easier to write and read static properties definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment