An example is going to be easier than an explanation,below a dateTime class that I’ve written :
define([
'jquery',
'infrastructure/libWrapper/Backbone',
'underscore' ],
function($, Backbone, _ ){
return Backbone.Model.extend({
initialize: function(){
if(this.get('value') == null){
this.set('value', new Date());
}
else{
var parts = this.get('value').match(/\d+/g);
this.set('value', new Date(parts[0], parts[1] - 1 , parts[2], parts[3], parts[4], parts[5]));
}
},
minus : function(dateTime){
return this.get('value').getTime() - dateTime.get('value').getTime();
},
toISOString : function(){
return this.get('value').toISOString();
},
defaults:{
value: null}
});
});
If I want to implement the method : “function plus(duration) {}” that should return a dateTime, how can I do that ?
Save model before returning it or better add it the same way you did with
minus