ES6 - Call static method within a class

Shlomi picture Shlomi · Jun 29, 2015 · Viewed 49.4k times · Source

I have this class which does an internal call to a static method:

export class GeneralHelper extends BaseHelper{
     static is(env){
          return config.get('env:name') === env;
     }

     static isProd(){
         return GeneralHelper.is('prod');
     }
 }

Are there any keywords I can use to replace the class name in the line below:

GeneralHelper.is('prod');

In PHP there are self, static etc. Does ES6 provide anything similar to these?

TY.

Answer

Otto Nascarella picture Otto Nascarella · Feb 26, 2017

if you are calling the static function from inside an instance, the right way to refer to the class static function is:

this.constructor.functionName();

es6 call static methods