我正在尝试在Typescript中创建Backbone.js视图。我收到以下错误:
TypeError: ExampleView is not a constructor in http://localhost:57258/Tests/spec/ExampleViewTest.js (line 17)
我的视图实例化如下:
var view = new ExampleView();
视图声明如下:
///<reference path="../Scripts/typings/backbone/backbone.d.ts"/>
class ExampleView extends Backbone.View {
constructor(options?: Backbone.ViewOptions) {
super(options);
}
};
更新:查看“已编译的javascript文件”,浏览器提供的错误位于倒数第二行:Backbone未定义。我该如何导入它?
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var ExampleView = (function (_super) {
__extends(ExampleView, _super);
function ExampleView() {
_super.apply(this, arguments);
}
return Av;
})(Backbone.Model);
//# sourceMappingURL=av.js.map
答案 0 :(得分:0)
Backbone未定义。我该如何导入它?
使用脚本标记。或者像requirejs
这样的外部模块加载器以及AMD模块(--module amd
)。更多:https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1