決議,發生錯誤在我的代碼的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