版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_36282409/article/details/83823834
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript" charset="UTF-8">
/**
* this对象:
* this对象是在运行时基于(函数)的执行环境绑定的,在全局函数中,this等于window。
* 而当函数被作为某个对象的方法调用时,this等于那个对象。
* 也就是说this关键字总是指代调用者(也是就是说,谁调用了我,我就指向谁)。
*/
//eg:this对象是在运行时基于(函数)的执行环境绑定的
var k = 10;
function test(){
this.k = 20;
}
// alert(k);
//test();
//window.test();
test();
// alert(test.k);//返回undefined
// alert(window.k);
alert(k);
</script>
</head>
<body>
<h1>New Web Project Page</h1>
</body>