日期:2014-05-16 浏览次数:20385 次
var name = "The Window";
var object = {
name: "My Object",
getNameFunc: function () {
return this.name;
}
};
alert((object.getNameFunc = object.getNameFunc)());
<script type="text/javascript">
<!--
var name = "I am Window";
var object = {
name: "My Object",
getNameFunc: function () {
return this.name;
}
};
var a= object.getNameFunc; //将函数从object中复制出来,这时函数的this指向window
alert(a());
//(var b=a),将返回a,同理(a=a) 返回a 所以这里返回的就是独立的匿名函数,效果等同于上面的代码
alert((object.getNameFunc = object.getNameFunc)());
//-->
</script>
var tempFunc = (object.getNameFunc = object.getNameFunc);
tempFunc();