類名繫結

ClassDeclaration 的名稱在不同的範圍內以不同的方式繫結 -

  1. 定義類的範圍 - let 繫結
  2. 類本身的範圍 - 在 {} 中的 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