我正在做类似的事情:
class ProblemAnswersModel extends Backbone.Model {
parse(response) {
this.relations = {"interventions" : Backbone.Collection};
this.set(response);
}
}
但我想做:
class ProblemAnswersModel extends Backbone.Model {
this.relations = {"interventions" : Backbone.Collection};
parse(response) {
this.set(response);
}
}
我试过了
class ProblemAnswersModel extends Backbone.Model {
relations = {"interventions" : Backbone.Collection};
parse(response) {
this.set(response);
}
}
但这似乎创建了一个单独的变量,而不使用底层的主干变量。
最佳答案
如果您的意思是 Backbone.Collection
作为类型而不是构造函数,则应该像这样声明关系
:
class ProblemAnswersModel extends Backbone.Model {
relations: { "interventions" : Backbone.Collection };
parse(response) {
this.relations = { "interventions" : someBackboneCollectionInstance };
this.set(response);
}
}
如果你想向原型(prototype)添加关系:
ProblemAnswersModel.prototype.relations = ...
关于javascript - 覆盖 TypeScript 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31861715/