Javascript 视图不是Typescript下主干的构造函数
我正在尝试在Typescript中创建Backbone.js视图。我得到以下错误:Javascript 视图不是Typescript下主干的构造函数,javascript,backbone.js,typescript,Javascript,Backbone.js,Typescript,我正在尝试在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/ba
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);
}
};
视图声明如下:
var view = new ExampleView();
///<reference path="../Scripts/typings/backbone/backbone.d.ts"/>
class ExampleView extends Backbone.View {
constructor(options?: Backbone.ViewOptions) {
super(options);
}
};
主干未定义。我如何导入它
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
使用脚本标记。或者像
requirejs
这样的外部模块加载器以及AMD模块(--module AMD
)。更多信息:通常主干视图是使用Backbone.View.extend(…)
创建的,但您似乎在使用本机JavaScript原型继承。这可能就是问题所在。您可能需要改用Backbone.View.extend(…)
。我之所以使用“extends”关键字,是因为建议在主干的Typescript版本中使用它。他们实际上阻止了主干.View.extend(…)