关于VAR、FUNCTION声明

版权声明:任先阳 任 先 阳 任先 先阳,ifgm.cn、www.ifgm.cn、nvcc.cc、www.nvcc.cc、sbfox.com、www.sbfox.com https://blog.csdn.net/qq_39571197/article/details/86624592

结论:全局性的使用VAR、FUNCTION声明,都会挂载(覆盖)到window对象

 1、测试如下代码

var open = 2;
console.log(open);
console.log(window.open);
console.log(window); // 查看 open 属性
function open(){
}
open.info = "123456";
console.log(open.info);
console.log(window.open.info);
console.log(window); // 查看 open 属性

【完】

https://www.imooc.com/qadetail/137684,可以看下这个问题,只不过是重写了open方法,导致了死循环...

<!DOCTYPE html >
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>浏览器对象_编程练习</title>
  <script type="text/javascript">
    function back() {
      window.history.back();
    }

    function change() {
      setTimeout("open2()", 5000);

    }

    function open2() {
      //location.assign("http://www.imooc.com");
      window.open('http://www.imooc.com', '_self');
//这里如果用window.open.('http://www.imooc.com');就不行了
    }

    change();
  </script>
</head>
<body>
<input type="button" value="返回上页面" onclick="back()"/>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/qq_39571197/article/details/86624592