由于 ES6 类只是JavaScript 现有的基于原型的继承 [1]的语法糖,因此(IMO)提升它的定义是有意义的:
var foo = new Foo(1, 2); //this works
function Foo(x, y) {
this.x = x;
this.y = y;
}
但以下将不起作用:
var foo = new Foo(1, 2); //ReferenceError
class Foo {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
为什么不提升 ES6 类?