簡體   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