打字稿扩展关键字不起作用
Typescript extends keyword not working
我正在使用 Visual Studio、Phaser 和 Typescript 开发我的第一款游戏。
当我使用 extends 关键字时,我的 类 无法工作
这个有效:
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);
}
}
这不是:
class Game extends Phaser.Game{
constructor() {
// init game
super(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State);
}
}
我一整天都在努力解决这个问题,但没有成功,有人可以解释一下吗?
phaser.js 的脚本标签需要位于脚本的脚本标签之上。
每个脚本都按顺序运行,您的第二个示例直接依赖于 Phaser
对象,该对象在运行时已被创建。
我正在使用 Visual Studio、Phaser 和 Typescript 开发我的第一款游戏。
当我使用 extends 关键字时,我的 类 无法工作
这个有效:
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);
}
}
这不是:
class Game extends Phaser.Game{
constructor() {
// init game
super(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State);
}
}
我一整天都在努力解决这个问题,但没有成功,有人可以解释一下吗?
phaser.js 的脚本标签需要位于脚本的脚本标签之上。
每个脚本都按顺序运行,您的第二个示例直接依赖于 Phaser
对象,该对象在运行时已被创建。