What sort of issues with ES5 are static class methods in ES6 supposed to deal with?
The Babel documentation has the following example in its section regarding ES6 classes, though it does not actually state what this pattern accomplishes.
Classes support prototype-based inheritance, super calls, instance and static methods and constructors
class SkinnedMesh extends THREE.Mesh {
constructor(geometry, materials) {
super(geometry, materials);
this.idMatrix = SkinnedMesh.defaultMatrix();
this.bones = [];
this.boneMatrices = [];
//...
}
update(camera) {
//...
super.update();
}
static defaultMatrix() {
return new THREE.Matrix4();
}
}
Consider class that contains only static methods:
It is quite convenient way of organizing code - put stuff in namespaces.
That's other than standard static method use cases in other OOP languages.
If you compile ES6 code with Babel, and some class contains a static method, ES5-generated code will be just adding that static function to the constructor function.
So, this
ES6ES2015 code:...equals (in ES5):
Why you need static functions? Well, transpiled code won't support statics at all, since even functions are objects and static functions are turned into own properties of constructor function.
Static functions or properties can be used to implement factory pattern:
Anyway, static member usage is a very diffuse topic and it goes out of scope of an objective answer. It has a lot of use cases and these are universal to any programming language.