2014-07-03 184 views
1

我在學習(開發)一些使用HTML5和TypeScript的遊戲。我寫這段代碼:函數內函數調用

class GameMap { 
    private sheet: RaphaelPaper; 
    private tiles: Tile[]; 
    constructor() { 
     this.tiles = []; 
     this.sheet = Raphael(document.getElementById('canvas_container'), 500, 500); 
    } 

    render() { 
     var tileWidth = 20; 
     var tileHeight = 20; 

     for (var i = 0; i < 30; i++) { 
      for (var j = 0; j < 30; j++) { 
       this.tiles.push(new Tile(i, j)); 
       var rectangle = this.sheet.rect(i * tileWidth, j * tileHeight, tileWidth, tileHeight); 
       rectangle.hover(this.tileMouseOn(), this.tileMouseOut(), rectangle, rectangle); 
      } 
     } 
    } 

    tileMouseOn() { 
     this.attr({ 'stroke-width': 1 }); 
    } 

    tileMouseOut() { 
     this.attr({ 'stroke-width': 0 }); 
    } 
} 

問題是用rectangle.hover()函數。我收到以下錯誤:

Supplied parameters do not match any signature of call target: 
Could not apply type 'Function' to argument 1 which is of type 'void'. 

此功能有什麼問題?

回答

2

hover()期待函數引用爲2個第一個參數。試試這個:

rectangle.hover(this.tileMouseOn, this.tileMouseOut, rectangle, rectangle); 
+1

美麗:)非常感謝。我嘗試了一切,除了這個「代表」:P – Fka