01前端/JS - 严格模式

class 中的代码总是在严格模式下执行。

1
2
3
4
5
6
7
8
9
class C4 {
constructor() {
//Uncaught TypeError: Cannot set property foo of #<C4> which has only a getter
this.foo = "test";
}
get foo() {}
}

let obj3 = new C4();
1
2
3
4
5
6
7
8
9
10
11
12
class C1 {
constructor() {
// Uncaught TypeError: Cannot set property foo of #<C2> which has only a getter
this.foo = "test";
}
}

class C2 extends C1 {
get foo() {}
}

let obj = new C2();