<html>
<body>
<h2>JavaScript "this"</h2>
<p>此例演示在箭头函数中,“this”关键字表示拥有该函数的对象,无论是谁调用该函数。</p>
<p>点击按钮再次执行“hello”函数,你会看到“this”仍然代表 window 对象。</p>
<button id="btn">点击我!</button>
<p id="demo"></p>
<script>
var hello;
hello = () => {
document.getElementById("demo").innerHTML += this;
}
//window 对象调用函数:
window.addEventListener("load", hello);
//button 对象调用函数:
document.getElementById("btn").addEventListener("click", hello);
</script>
</body>
</html>