繁体   English   中英

我的/index.html重定向到/ [object Object]

[英]my /index.html is redirecting to /[object Object]

我正在尝试学习一些JavaScript,并且一直将我的代码编写为.js文件并将其导入到index.html页面中。

在修复所有错误之前,页面和画布已正确加载。 现在,页面重定向后,firebug才能检查任何内容。 并且仅显示错误“无法在[object Object]中找到文件”。

index.html代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Life</title>
    <script src='js/Map.js'></script>
    <script src='js/Game.js'></script>
    <script src='js/Animal.js'></script>
    <script src='js/Block.js'></script>
    <script src='js/Food.js'></script>
    <script src='js/Shapes.js'></script>
    <script src='js/Menu.js'></script>
    <style>
        #screen {
            display:block; 
            margin:0 auto; 
            background-color:#000; 
        }
        .fpsmeter {
            padding: 0;
            margin: 0;
            width: 100%;
            text-align: center;
        }
        .fpsmeter p {
            margin-top: 0px;
            margin-bottom: 0px;
        }
    </style>
</head>
<body>
    <canvas id='screen' width='1200' height='500'></canvas>
    <div id="fpscontainer"></div>
</body>
</html>

我不确定在哪里可以找到解决问题的方法。

https://dl.dropboxusercontent.com/u/23801920/Html5/life/index.html

链接到js文件。

https://dl.dropboxusercontent.com/u/23801920/Html5/life/js/Animal.js

“” Block.js

“” Food.js

“” Game.js

“” Map.js

“” Menu.js

“” Shapes.js

我知道可能还有很多其他问题,但是我想在这个问题上寻求帮助。

我相信ChiChou回答了我的问题,但在确定之前我还有一些错误检查要做!

您一定在某个地方错过了new操作员。

查看以下代码:

Animal = function (location, age, direction, dna, parentA, parentB){
//this = Block('animal');
this.type = 'animal';
this.age = age;
this.location = location;
         ^^^^^^^^

您应该使用var animal = new Animal()创建Animal的新实例。 如果直接调用函数Animal() ,则this函数内部将引用window 将值分配给window.location将进行重定向。

因此,您实际上调用了以下内容:

window.location = location.toString();

Mofidy this.locationthis._location会暂时解决这个问题,但对于从根本上解决,你应该找出你调用该函数以错误的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM