Typescript extends keyword not working

倖福魔咒の 提交于 2020-01-07 06:55:32

问题


I'm developing my first game using Visual Studio, Phaser and Typescript.

I can't get my classes to work when I use the extends key word

This works:

class Game  {

game: Phaser.Game;

constructor() {
    // init game
    this.game = new Phaser.Game(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State);
}
}

This does not:

class Game extends Phaser.Game{

constructor() {
    // init game

    super(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State);
}
}

I've been trying to figure this out all day without success, can anybody shed some light on it?


回答1:


The script tag for phaser.js needs to be above the script tag for your script.

Each script runs in order and your second example has an immediate dependency on the Phaser object already being created as soon as it runs.



来源:https://stackoverflow.com/questions/32802777/typescript-extends-keyword-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!