访问对 class 的引用

Accessing reference to class

给定:

function GameManager(){...};

GameManager.prototype.draw = function(){
    this.world.removeChildren() // <-- Error is here; "this" is PIXI.Sprite, not GameManger
}

GameManager.prototype.text = function(func){
    let spr = new PIXI.Sprite();
    spr.pointerup = func;
    this.world.addChild(spr);
}

我想在调用时访问"GameManager"

this.text(this.drawgame);

this.world.removeChildren() //GameManager.prototype.draw

而不是我得到 PIXI.Sprite 因为我调用 spr.pointerup = func

是否有可能获得 GameManager 的引用而不是 PIXI.Sprite

我不想使用全局变量

 this.text(this.drawgame);

这里你失去了上下文。您需要 上下文:

 this.text(this.drawgame.bind(this));