This is not a valid syntax for declaring properties in a class. Instead, declare them in the constructor.
class Foo { constructor() { this.f1 = undefined; } }
Then you can get them using Object.keys .
Using experimental functions in Babel will allow you to declare properties using this syntax, but their values ββmust be declared.
class Foo { f1 = 0; ... }
As with access to getters, getters are not enumerable by default and cannot be accessed using Object.keys or any similar mechanism. However, you can create enumerated getters using Object.defineProperty .
Object.defineProperty(bar, 'f2', { get() { return "a"; } });
If you use the experimental features of ES7, you can apply decorator to the class method and get the same behavior. See Babel Example .
class Foo { @enumerable() get b2() { return "a"; } } function enumerable() { return function(target, key, descriptor) { if (descriptor) { descriptor.enumerable = true; } } }
source share