对于以下代码,我想知道 ES6 类中这种行为背后的原因:
class One {
//why the following code is not allowed.
let check = false;
const PI = 3.14;
var v = 'Hello';
//why the following code is allowed.
chk = false;
Pi = 3.14;
vv = "Hi";
}
我知道我可以编写如下代码,但我想知道上述代码背后的真正原因。
class Sample {
constructor(x, y) {
this.x= x;
this.y= y;
}
}