我正在学习打字稿,我对这门课有疑问,我现在的代码是
export class Window {
public title: string;
public width: number;
public height: number;
public canvas;
public ctx;
public constructor(title: string, width: number, height: number) {
this.title = title;
this.width = width;
this.height = height;
this.createCanvas();
}
public createCanvas(): void {
this.canvas = <HTMLCanvasElement>document.createElement('canvas');
this.ctx = this.canvas.getContext("2d");
this.canvas.width = 500;
this.canvas.height = 500;
document.body.appendChild(this.canvas);
}
export class Game {
private title: string;
private width: number;
private height: number;
public constructor() {
}
window: Window = new Window("titi", 100, 100);
} …Run Code Online (Sandbox Code Playgroud)