If I want to add a custom property to my base model, is it better to do this? Is there a better way or a completely different approach to the functionality I want to achieve?
var myModel = Backbone.Model.extend({ defaults:{ monthly_amount: 100 }, initialize: function(model, options){ var m = this; Object.defineProperty(this,"yearly_amount",{ get: function() { return (m.get("monthly_amount") * 12); }, set: function(value) { m.set("monthly_amount", (value/12) ); } }); } });
Thanks!
Edit: the property is "virtual"; I do not want it to be in the model attributes when saving the model to the server.
homtg
source share