简体   繁体   English

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

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

I am trying to learn some javascript, and have been writing my code as .js files and importing them to an index.html page. 我正在尝试学习一些JavaScript,并且一直将我的代码编写为.js文件并将其导入到index.html页面中。

Before all my errors were fixed, the page and canvas loaded properly. 在修复所有错误之前,页面和画布已正确加载。 Now the page redirects before firebug can check for anything. 现在,页面重定向后,firebug才能检查任何内容。 And just displays the error "cannot find the file at [object Object]". 并且仅显示错误“无法在[object Object]中找到文件”。

the index.html code is below: 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>

I'm not really sure where to look to find the solution to the problem. 我不确定在哪里可以找到解决问题的方法。

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

Links to js files. 链接到js文件。

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

" "Block.js “” Block.js

" "Food.js “” Food.js

" "Game.js “” Game.js

" "Map.js “” Map.js

" "Menu.js “” Menu.js

" "Shapes.js “” Shapes.js

I know there are probably a lot of other problems, but I'd just like help with this problem. 我知道可能还有很多其他问题,但是我想在这个问题上寻求帮助。

I believe ChiChou answered my question, but I have a bit of bug checking to do before I know for sure! 我相信ChiChou回答了我的问题,但在确定之前我还有一些错误检查要做!

You must have missed new operator somewhere. 您一定在某个地方错过了new操作员。

Check out the following code: 查看以下代码:

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

You should use var animal = new Animal() to create a new instance of Animal. 您应该使用var animal = new Animal()创建Animal的新实例。 If you directly call function Animal() , this inside the function will be a reference to window . 如果直接调用函数Animal() ,则this函数内部将引用window Assigning value to window.location will make a redirection. 将值分配给window.location将进行重定向。

So you actually call something like: 因此,您实际上调用了以下内容:

window.location = location.toString();

Mofidy this.location to this._location will temporary solve this, but for a fundamental solution, you should find out where you call the function in a wrong way. Mofidy this.locationthis._location会暂时解决这个问题,但对于从根本上解决,你应该找出你调用该函数以错误的方式。

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

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