Q:

Backbonejs: How would I attach a constructor for every instance of a model using prototype?

How would I attach a constructor for every instance of a model using prototype? I have been trying to modify the constructor method when an instance of Backbone.Model is created. BuT I do not want to attach a constructor method to each model I create individually. Adding a prototype of initialize works; the only issue is if initialize is passed with the model it overrides it via the underscore extend method.
I tried this
Backbone.Model.prototype.constructor = function(attributes, opts) {
        console.log('hi');
        Backbone.Model.prototype.constructor.call(this, attributes);
};

only problem is, it doesn't work outside of the extend; it will only get called if constructor is inside the object you extend the model with when creating a new instance.
I just need to run some code when an instance of each model is created. I want to perform some auto binding work with node's socket.io framework.

A:

It's not recommended to mess with the internals of backbone inheritance and use the provided methods and flow to achieve model manipulation on initialization. To do that - in a similar fashion as with collections, views or routers you have an initialization method that you should override that takes the role of a constructor.
If you need to alter all your models just create a new base class that you will later use as a super class for all your models and then if you need to overwrite the initialization method of subclasses remeber to call the super class initializer using the built in backbone class __super__ property.
initialize: function() {
    this.constructor.__super__.initialize.call(this);
    // whatever
},

Altering the core of backbone will never do good for you in the long run as it my prevent you from being able to easily update to new version if they would introduce conflicting changes.
I've been there and done that - and after doing it I'd recommend not following this path to anybody!

