ES6 class variable alternatives

前端 未结 15 2129
长发绾君心
长发绾君心 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:12

    Babel supports class variables in ESNext, check this example:

    class Foo {
      bar = 2
      static iha = 'string'
    }
    
    const foo = new Foo();
    console.log(foo.bar, foo.iha, Foo.bar, Foo.iha);
    // 2, undefined, undefined, 'string'
    

提交回复
热议问题