Backbone: initialize vs constructor

October 20, 2015

I seem to run into this over and over in my Backbone projects. What is the difference between initialize and constructor when creating Backbone object (models, collections, views)?

According to this GitHub issue response by tbranyen:

"constructor runs before Backbone sets up the structure. initialize is called inside the structure’s constructor function. So basically if you need to augment anything before Backbone sets up the structure, use constructor if you need to augment anything after Backbone sets up the structure use initialize.”

So almost always use initialize().  If you do use constructor(), remember that you will most likely need to call the ‘parent’ constructor in your constructor.