For example, in regular functions:

class Header {
constructor() {
this.color = "Blue";
}

//Regular function:
changeColor = function() {
document.getElementById("demo").innerHTML += this;
}
}

const myheader = new Header();

//The window object calls the function:
window.addEventListener("load", myheader.changeColor);

//A button object calls the function:
document.getElementById("btn").addEventListener("click", myheader.changeColor);

For example, in Arrow functions:

class Header {
constructor() {
this.color = "Blue";
}

//Arrow function:
changeColor = () => {
document.getElementById("demo").innerHTML += this;
}
}

const myheader = new Header();


//The window object calls the function:
window.addEventListener("load", myheader.changeColor);

//A button object calls the function:
document.getElementById("btn").addEventListener("click", myheader.changeColor);

Categorized in:

ReactJS

Tagged in:

, , , , , , , , , , , ,

Share Article:

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO