I’m building an html page that uses backbone.js
How can I override the constructor of a backbone Model?
Let me explain with an example:
I have a 2 models, let say M1, and M2.
In M2 constructor, I want to put and M1
m1=new M1({somedata:""});
m2=new M2({m1Ref: m1)
If I do this m2 will contain a reference to m1.
However what I need is m2 to have m1 data copied (somedata attribute value should be copied to m2), so I’ve tried to overwrite the constructor, and change the data received there
var M2=Backbone.Model.extend({
constructor: function(data){
data=_.extend(data, data.timmer);
data.timmer=undefined;
Backbone.Model.prototype.constructor.call(this, data);
}
}
But this is not working properly.
How should override the constructor properly?
Thanks
Ok, found the solution.