javascript - How to use the feature of directly declaring attributes in js class in babel
黄舟
黄舟 2017-05-16 13:25:40
0
1
433

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?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
大家讲道理

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template