决议,发生错误在我的代码的javascript无法调用方法中__prototype__表示对象[对象的对象]无方法“显示器”
我测试出moo4q jQuery的MooTools的合成(HTTP://moo4q.com/)在一个简单的游戏,并遇到一个问题。下面是代码,是造成问题的片段:
// write score counter, puts up overlay, load image
initGame: function() {
this.app.unbind('loadingDone',this.initGame);
this.setupHUD();
this.gameObjects['scoreCounter'].html('1000');
var imgLib = this.imgs[this.gameType];
var img = imgLib.getUniqueImage();
this.log(img);
img.display(this.gameObjects['imageHolder']);
this.gameObjects['overlay'].fillRect(0, 0, 320, 460);
$(this.gameObjects['overlay'].canvas).bind('click', $.proxy(this.pokeHole, this));
},
作为解释,this.gameObjects [“imageHolder的”]传递给IMG对象画布背景来告诉它在哪里画。特别是在'img.display(this.gameObject ['imageHolder']);我从Chrome中
呼吁行日志跟踪的输出得到错误
Uncaught TypeError: Object [object Object] has no method 'display'
只是调用之前(这仅仅是一个包裹window.console.log)是:
[Class.newClass.constructor
file: Object
keyword_list: Array[1]
options: F
__proto__: Object
canvasContext: null
checkResponse: function(){
constructor: function(){
display: function(){
file: null
initialize: function(){
keyword_list: Array[0]
log: function(){
options: Object
__proto__: Object
我想,也许,它会调用显示为proto扩展?但似乎不是。 this.imgs [this.gameType]是一个ImageContainer类。 getUniqueImage看起来是这样的:
// gets a random image from the imgsShown array, then removes it
// so that subsequent calls to getUniqueImage will always
// be unique. Refills imgsShown if empty.
getUniqueImage: function() {
// copy over the img array if imgsShown array is empty
if(this.imgsShown.length == 0) this.imgsShown = this.imgs.slice(0);
var rand = Math.floor(Math.random() * this.imgsShown.length);
return this.imgsShown.splice(rand,1);
}
这里
全貌(符被点击时动物):
http://www.clumsyfingers.net/projects/game/revealer/
最相关的文件在/ apps目录,我已经离开开放
http://www.clumsyfingers.net/projects/game/revealer/app/
Halp?
原来是getUniqueImage函数返回值的错误。我正在返回一个数组(由拼接函数创建)而不是对象。作为参考,Chrome的调试中的[]表示记录的参数是一个数组。 – clumsyfingers 2011-03-18 01:16:29