Accessing parent class in Backbone

后端 未结 8 846
广开言路
广开言路 2020-12-07 14:40

I need to call the initialize method of the parent class, from inside the inherited MyModel-class, instead of completely overwriting it as I am doi

相关标签:
8条回答
  • 2020-12-07 15:17

    Try

    MyModel = BaseModel.extend({
        initialize: function() {
            BaseModel.prototype.initialize.apply(this, arguments);
            // Continue doing specific stuff for this child-class.
        },
    });
    
    0 讨论(0)
  • 2020-12-07 15:21

    I think it'd be

    MyModel = BaseModel.extend({
        initialize: function() {
            this.constructor.__super__.initialize.call(this);
            // Continue doing specific stuff for this child-class.
        },
    });
    
    0 讨论(0)
提交回复
热议问题