在函数内部调用函数

时间:2014-07-03 12:51:06

标签: raphael typescript

我正在尝试使用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'.

这个功能出了什么问题?

1 个答案:

答案 0 :(得分:2)

hover()期望将函数引用作为2个第一个参数。试试这个:

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