Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing parent class in Backbone

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.     }, }); 
like image 602
Industrial Avatar asked Jan 23 '12 11:01

Industrial


2 Answers

Try

MyModel = BaseModel.extend({     initialize: function() {         BaseModel.prototype.initialize.apply(this, arguments);         // Continue doing specific stuff for this child-class.     }, }); 
like image 83
Yury Tarabanko Avatar answered Oct 08 '22 06:10

Yury Tarabanko


MyModel = BaseModel.extend({     initialize: function() {         MyModel.__super__.initialize.apply(this, arguments);         // Continue doing specific stuff for this child-class.     }, }); 
like image 33
Raynos Avatar answered Oct 08 '22 07:10

Raynos