类名绑定

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