DeNA JSX (AltJS): Canvas に描画

// DOM 操作を行う (document.getElementById など) 場合は、このモジュールを import する
// または Canvas 系の操作に使う
import "js/web.jsx";

class CanvasController {
    var canvas          :HTMLCanvasElement;
    var context         :CanvasRenderingContext2D;
    
    function constructor(canvas:HTMLCanvasElement) {
        this.canvas = canvas;
        this.context = canvas.getContext("2d") as CanvasRenderingContext2D;
        
        this.drawString();
    }
    
    // 
    function drawString():void {
        this.context.fillStyle = "#ff0000";
        
        this.context.font = "9pt Helvetica";
        this.context.textAlign = "center";
        this.context.fillText("hoge", 50, 50);
    }
}


class _Main {
    static function main(args : string[]) : void {
        log "Hello, world!";
        var canvas = dom.id("canvas");
        log c;
        new CanvasController(canvas as HTMLCanvasElement);
    }
}

変換コマンド

jsx --executable web --output canvas.js CanvasController.jsx