Created
March 9, 2012 16:03
-
-
Save Takazudo/2007253 to your computer and use it in GitHub Desktop.
Backbone.js date convert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MyModel = Backbone.Model.extend({ | |
initialize: (attrs){ | |
var self = this; | |
self.updateDate(); | |
self.bind('change:date', function(){ | |
self.updateDate(); | |
}); | |
}, | |
updateDate: function(){ | |
var date = this.get('date'); | |
if(_.isString(date)){ | |
this.set('date', new Date(date)); | |
} | |
} | |
}); | |
or | |
var MyModel = Backbone.Model.extend({ | |
set: function() { | |
Backbone.Model.prototype.set.apply(this, arguments); | |
this.updateDate(); | |
}, | |
updateDate: function(){ | |
var date = this.get('date'); | |
if(_.isString(date)){ | |
this.set('date', new Date(date)); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment