Marionette 使用打字稿的模块

Marionette Module using typescript

如何使用类型脚本创建木偶模块。我看到了这个 how to write marionettejs module using typescript? 但它对我的情况没有用。我创建了类似

的模块
class TestModule extends Marionette.Module {
    constructor(options) {
        if (!options)
            options = {};
        var marionetteApp = new MarionetteApp();
        marionetteApp.module("myModule", {
            startWithParent: false
        });
        super("myModule", marionetteApp);
    }
}

但是显示错误 http://localhost/Scripts/backbone.marionette.js

中第 5 列第 3561 行的未处理异常

0x800a138f - JavaScript 运行时错误:无法获取 属性 'initialize' 未定义或空引用

我做错了什么。我是 Marionette 和打字稿的新手。使用打字稿创建 marionette 模块的正确步骤是什么 我的申请代码是

class MarionetteApp extends Marionette.Application {
    headerRegion: Marionette.Region;
    leftRegion: Marionette.Region;
    centerRegion: Marionette.Region;
    constructor() {
        super();
        this.on("start", this.initializeAfter);
        this.addRegions({ headerRegion:"#headerContainer",leftRegion:"#leftContainer",centerRegion:"#centerContainer"});
    }
    initializeAfter() {
        //alert("started")
        this.headerRegion.show(new HeaderView());
        this.leftRegion.show(new leftView());
        this.centerRegion.show(new CenterView());
        var MyModule = new TestModule("Test");
        //MyModule.start();
    }
}

我使用以下代码解决了这个问题。将模块包装在 class 内。它按预期工作。如果我错了,请纠正我,有人知道正确的程序

class TestModule {
mod: any;
constructor() {
    var marionetteApp = new MarionetteApp();
    this.mod = marionetteApp.module("myModule", {
        startWithParent: false,
        initialize: function(){
            console.log("initialized");
        },
        define: function () {
            console.log("defined");
        }
    });

    this.mod.on("start", this.onStart);
}
start() {
    this.mod.start();
}
onStart() {
    console.log("Module started")
}

}

初始化代码

var MyModule = new TestModule();
    MyModule.start();