📜  静态方法 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:48.350000             🧑  作者: Mango

代码示例2
class Repo {
  static getName() {
    return "Repo name is modern-js-cheatsheet"
  }
}

// Note that we did not have to create an instance of the Repo class
console.log(Repo.getName()) // Repo name is modern-js-cheatsheet

let r = new Repo();
console.log(r.getName()) // Uncaught TypeError: r.getName is not a function