I'm learning ES6 classes. Is there a way to make helper functions (eg for data munging) accessible to the constructor, but also elsewhere, so that I'm not typing out the function twice (as an IIFE in the constructor and a static class method too)?
Eg at the moment I'm doing because getDimensions
is not callable in the constructor:
class Foo {
constructor(data){
this._data = data;
let dimensions = function(data){
//return some dimensions
}(data);
this._x = d3.scaleLinear().domain([dimensions])...
}
static getDimensions(someData){
//same calcs as the constructor IIFE
}
updateScale(newData){
let dimensions = getDimensions(newData);
this.x = d3.scaleLinear().domain([dimensions]);
}
}
Is it possible/sensible to get myself a static helper method that I can use in my prototype methods and in the constructor?