Why can't I use arrow functions with an assignment expression in ES2015 classes?
Because this is not how the syntax of the ES2015 class is developed - for now , see the line below.
Is there any short way to reach my goal?
Itโs not clear to me that you want classes in general, just an object:
const List = { map: f => xs => xs.map(x => f(x)), of: x => [x] };
(You said that extension is important for what you do.)
But if you want List extend Array (for example, you will have instances), but then add these statics to them, you will need two steps:
class List extends Array { } Object.assign(List, { map: f => xs => xs.map(x => f(x)), of: x => [x] });
If you want them to be non-enumerable or non-configurable, etc., you need Object.defineProperties , not Object.assign ; I will leave this as an exercise for the reader ...
Here's a suggestion for stage 2 for class fields, including static fields. If he proceeds to step 4, he will eventually become part of the upcoming language specification (perhaps ES2018, it is unlikely at the moment you need to make ES2017, but you never know).
This will allow static fields to be declared inside the class, almost exactly as you showed them:
If you upgrade from Babel, you can say that it includes Stage 2 offers.
Tj crowder
source share