首页 > 其他 > 详细

(0, eval)("this")

时间:2017-03-25 17:51:50      阅读:581      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
var name = "The window";
var object1 = {
name: "My object",
getNameFunc: function(){
var that = (0,eval)("this"); //返回"the window
// var that = this; //返回"My object"
return function(){
// that = this;
return that.name;
};
}
};
alert(object1.getNameFunc()());
</script>
</head>
<body>

</body>
</html>

(0, eval)逗号表达式返回值再调用函数,将引发this值指向全局对象。所以that = (0, eval)("this"),表面上结果为that = this,和直接that = this的形式一样,但是此时的this并非指向object1,而是指向window

(0, eval)("this")

原文:http://www.cnblogs.com/gumptious/p/6617594.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!