Skip to content

Instantly share code, notes, and snippets.

@theotherzach
Last active December 17, 2015 14:18
Show Gist options
  • Select an option

  • Save theotherzach/5623090 to your computer and use it in GitHub Desktop.

Select an option

Save theotherzach/5623090 to your computer and use it in GitHub Desktop.
Thinking about how to approach numbers that are formatted as fancy strings but saved as numbers
window.app.views.BodyView = Backbone.View.extend({
el: $("body"),
events: {
"click #app-submit": "save",
},
save: function () {
var lineItem = $('#line-item').val()
this.model.saveWithFormat(lineItem)
}
});
app.models.LineItem = Backbone.Model.extend({
saveWithFormat: function(val){
// in the real version you do work here
this.set('lineItem' val);
return this // I like to always return myself when it makes sense for chaining
},
getFormatted: function(){
var number = this.get('lineItem');
// in the real version you do work here
return number;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment