Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js class method called when page loads

// 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
 
PREVIOUS NEXT
Tagged: #js #class #method #called #page #loads
ADD COMMENT
Topic
Name
1+9 =