ES6 class variable alternatives

前端 未结 15 2318
长发绾君心
长发绾君心 2020-11-22 06:04

Currently in ES5 many of us are using the following pattern in frameworks to create classes and class variables, which is comfy:



        
15条回答
  •  一生所求
    2020-11-22 06:23

    This is a bit hackish combo of static and get works for me

    class ConstantThingy{
            static get NO_REENTER__INIT() {
                if(ConstantThingy._NO_REENTER__INIT== null){
                    ConstantThingy._NO_REENTER__INIT = new ConstantThingy(false,true);
                }
                return ConstantThingy._NO_REENTER__INIT;
            }
    }
    

    elsewhere used

    var conf = ConstantThingy.NO_REENTER__INIT;
    if(conf.init)...
    

提交回复
热议问题