Last active
December 17, 2015 14:18
-
-
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
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
| 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) | |
| } | |
| }); |
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
| 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