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
thisreference, the static reference is for the current class and not its prototype. - easier to write and read static properties definition