Backbone.js 使用typescript的木偶模型
如何使用类型脚本创建木偶模块。我看到了这一点,但对我的情况没有用。我创建了一个模块Backbone.js 使用typescript的木偶模型,backbone.js,typescript,marionette,Backbone.js,Typescript,Marionette,如何使用类型脚本创建木偶模块。我看到了这一点,但对我的情况没有用。我创建了一个模块 class TestModule extends Marionette.Module { constructor(options) { if (!options) options = {}; var marionetteApp = new MarionetteApp(); marionetteApp.module("myModule"
class TestModule extends Marionette.Module {
constructor(options) {
if (!options)
options = {};
var marionetteApp = new MarionetteApp();
marionetteApp.module("myModule", {
startWithParent: false
});
super("myModule", marionetteApp);
}
}
但它显示出错误
中第3561行第5列的未处理异常
0x800a138f-JavaScript运行时错误:无法获取未定义或空引用的属性“initialize”
我做错了什么。我不熟悉木偶和打字。使用typescript创建木偶模块的正确步骤是什么
我的申请代码是
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 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();