我正在尝试学习一些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回答了我的问题,但在我确定之前,我有一些bug检查要做!
答案 0 :(得分:1)
您必须在某处错过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.location
到this._location
会暂时解决这个问题,但对于一个根本的解决方案,你应该找出你以错误的方式调用函数的地方。