覆盖TypeScript中的值

时间:2015-08-06 17:04:11

标签: javascript backbone.js typescript

我正在做类似的事情:

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);
    }
}

但这似乎创建了一个单独的变量,而不是使用底层骨干变量。

1 个答案:

答案 0 :(得分:1)

如果你的意思是Backbone.Collection而不是构造函数,你应该像这样声明relations

class ProblemAnswersModel extends Backbone.Model {
    relations: { "interventions" : Backbone.Collection };

    parse(response) {
        this.relations = { "interventions" : someBackboneCollectionInstance };
        this.set(response);
    }
}

如果你想为原型添加关系:

ProblemAnswersModel.prototype.relations = ...