<html>
<body>
<h1>Arrow Function</h1>
<p>The <strong>this</strong> keyword represents the Header object.</p>
<button id="btn">Click Me!</button>
<p><strong>this</strong> represents:</p>
<p id="demo"></p>
<script>
class Header {
constructor() {
this.color = "Red";
}
changeColor = () => {
document.getElementById("demo").innerHTML += this;
}
}
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);
</script>
</body>
<!-- Mirrored from www.w3schools.com/react/tryit.asp?filename=tryreact_es6_arrow_this by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 02:43:09 GMT -->
</html>