Making a custom backbone model constructor
Generally it is not need to make a custom constructor method for a backbone Model. However if for some reason it is needed doing so is as simple as just adding one to the object that is passed to Backbone Model.extend, when making the Model.
What to know before hand
This is an advanced post on backbone Models, be sure to check out my Main post on Models if you want to know more about them in general. Also I you are new to backbone you will want to check out my getting start post on backbone as well.
Is it okay to do this?
Sure is, it’s just that in most cases it is not needed, there is much that can be done with the initialize method. However if for some reason that does not cut it, it is also possible to define a constructor method for the model.
Making a custom constructor method for the model
So to do this just add a constructor method to the object that is passed to Backbone.Model.extend like this:
So far I have not found myself in many situations in which I need to do this, however I am still somewhat new to using backbone.