我有一个看起来像这样的课程
export class MyClass extends backbone.Model {
idAttribute: string = "Name";
private MyProperty: new backbone.Collection<MyCollectionItemClass>();
...
JavaScript中的:
private MyProperty: new backbone.Collection<MyCollectionItemClass>();
编译成:
_this.MyProperty= ();
给出了:
Uncaught SyntaxError:意外的令牌)
刚测过:
如果我删除private
MyProperty: new backbone.Collection<MyCollectionItemClass>();
结果使用相同的代码。
有人要求提供更完整的例子: 打字稿:
import _ = require("underscore");
import backbone = require("backbone");
export class MyClass extends backbone.Model {
private MyProperty: new backbone.Collection<MyCollectionItemClass>();
}
export class MyCollectionItemClass extends backbone.Model {
}
编译成JavaScript:
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
define(["require", "exports", "backbone"], function (require, exports, backbone) {
"use strict";
exports.__esModule = true;
var MyClass = (function (_super) {
__extends(MyClass, _super);
function MyClass() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.MyProperty = ();
return _this;
}
return MyClass;
}(backbone.Model));
exports.MyClass = MyClass;
var MyCollectionItemClass = (function (_super) {
__extends(MyCollectionItemClass, _super);
function MyCollectionItemClass() {
return _super !== null && _super.apply(this, arguments) || this;
}
return MyCollectionItemClass;
}(backbone.Model));
exports.MyCollectionItemClass = MyCollectionItemClass;
});
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"module": "amd"
},
"compileOnSave": true
}