📌  相关文章
📜  页面加载时调用的js类方法 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:58.178000             🧑  作者: Mango

代码示例1
// The cnstructor Method runs when you call a class method
// So for example
class App () {
  constructor() {}
  logHello() {
      console.log("Hello World");
  }
}

const test = new App();
// Immediately you have an instance of that class The constructor
// method is called, so if you want the logHello to log immediately then you can
// call it in the constructor like this

class App () {
  constructor() {
      this.logHello();
  }
  logHello() {
      console.log("Hello World");
  }
}

/* This will work on page load because any code not inisde a function or anything
runs on page load */

// Hope you understand and it helps