search

Home  >  Q&A  >  body text

javascript - How to use the feature of directly declaring attributes in js class in babel

Such a class:

class TestClass {
    name = 'abc';   //直接声明在class中
    static staticValue = 456;   //这是静态属性
    showName() {
        console.log(this.name);
    }
}

let cls = new TestClass();
cls.showName();

Is the above syntax supported in es? How to configure it if babel is used for translation?

黄舟黄舟2807 days ago454

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 13:27:40

    Static attributes should be remembered as an ES7 proposal.
    It seems that babel-stage2 will work. I don’t remember it clearly. You’ll know if you try it.

    reply
    0
  • Cancelreply