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 doing today.
How could I do this?
Here's what my code looks right now:
BaseModel = Backbone.Model.extend({ initialize: function(attributes, options) { // Do parent stuff stuff } }); MyModel = BaseModel.extend({ initialize: function() { // Invoke BaseModel.initialize(); // Continue doing specific stuff for this child-class. }, });
Try
MyModel = BaseModel.extend({ initialize: function() { BaseModel.prototype.initialize.apply(this, arguments); // Continue doing specific stuff for this child-class. }, });
MyModel = BaseModel.extend({ initialize: function() { MyModel.__super__.initialize.apply(this, arguments); // Continue doing specific stuff for this child-class. }, });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With