ES6 - 在类中调用静态方法 [英] ES6 - Call static method within a class

查看:52
本文介绍了ES6 - 在类中调用静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对静态方法进行内部调用的类:

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');

在 PHP 中有 selfstatic 等.ES6 是否提供类似的东西?

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

TY.

推荐答案

如果从实例内部调用静态函数,引用类的静态函数的正确方法是:

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

this.constructor.functionName();

从常规 ES6 类方法调用静态方法

这篇关于ES6 - 在类中调用静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆