这是es6的什么语法? - CNode技术社区

这是es6的什么语法?
发布于 10 年前 作者 Alexis374 6332 次浏览 最后一次编辑是 9 年前 来自 问答
class A {
 xhr: XMLHttpRequest;
 constructor(name='fuck'){
 this.name=name
 }
 
}
var a = new A('suck')
console.log(a.name)

constructor上面那一行。在react相关的代码里看到了类似的写法,用(babel)[https://babeljs.io/repl/] 编译,发现如果不同时勾选react,stage-0就会报错。分别报repl: Unexpected token (3:5) 和 repl: Missing class properties transform. 难道说facebook自己实现了部分语法?

2 回复

应该是对应不同级别,react也代表了某些语法级别,各人认为,不用纠结这个

·property: propertyType·是类属性声明,ES7里有,Babel用这个plugin transform https://babeljs.io/docs/plugins/transform-class-properties/

回到顶部

AltStyle によって変換されたページ (->オリジナル) /