我正在尝试学习一些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
"菜单.js
"Shapes.js
我知道可能还有很多其他问题,但我只是想帮助解决这个问题。
我相信ChiChou回答了我的问题,但在我确定之前,我还有一些bug检查要做!
您一定在某个地方遗漏了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();
Mofidythis.location
到this._location
将暂时解决此问题,但对于基本解决方案,您应该找出以错误方式调用函数的位置。