類名繫結
ClassDeclaration 的名稱在不同的範圍內以不同的方式繫結 -
- 定義類的範圍 -
let
繫結 - 類本身的範圍 - 在
{
和}
中的class {}
-const
繫結
class Foo {
// Foo inside this block is a const binding
}
// Foo here is a let binding
例如,
class A {
foo() {
A = null; // will throw at runtime as A inside the class is a `const` binding
}
}
A = null; // will NOT throw as A here is a `let` binding
功能不一樣 -
function A() {
A = null; // works
}
A.prototype.foo = function foo() {
A = null; // works
}
A = null; // works