I have this class which does an internal call to a static method:
export class GeneralHelper extends BaseHelper{
static is(env){
return config
It's the same as calling a method on an ordinary object. If you call the GeneralHelper.isProd()
method, the GeneralHelper
will be available as this
in the method, so you can use
class GeneralHelper {
static is(env) { … }
static isProd(){
return this.is('prod');
}
}
This will however not work when the method is passed around as a callback function, just as usual. Also, it might be different from accessing GeneralHelper
explicitly when someone inherits isProd
from your class and overwrites is
, InheritedHelper.isProd()
will produce other results.
If you're looking to call static methods from instance methods, see here. Also notice that a class which only defines static methods is an oddball, you may want to use a plain object instead.