对于下面的代码,我想了解 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;
}
}
var
、let
或const
,只会让人感到困惑。 - Felix Kling