<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Function - Study this</title>
<script type="text/javascript" charset="utf-8">
k = 10;
function test() {
this.k = 20;
document.write(this);
document.write('<br>' + '==================' + '<br>');
}
test();
document.write(k);
document.write('<br>' + '==================' + '<br>');
document.write(test.k);
</script>
</head>
<body>
</body>
</html>
- this对象是在运行时基于函数的执行环境绑定的。在全局函数中,this等于window,而当函数被作为某个对象的方法调用时,this等于那个对象。
- 也就是说this关键字总是指代调用者。