<html>
<head>
<title>javascript this的范围理解</title>
</head>
<body>
<script type="text/javascript">
//在javascript中,函数总是在一个特殊的上下文执行(称为执行上下文),如果你将一个对象的函数赋值给另外一个变量的话,这个函数的执行上下文就变为这个变量的上下文了
window.name = "1";
function scopeTest(){
console.log(this.name);
}
scopeTest(); //1
var foo = {
name:"2",
otherScopeTest:function(){
console.log(this.name);
}
}
foo.otherScopeTest(); //2
//javascript一切都是对象,所以将otherScopeTest函数对象传递给新的对象foo_anotherScopeTest
var foo_anotherScopeTest = foo.otherScopeTest;
foo_anotherScopeTest(); //1
</script>
</body>
</html>