Created
August 30, 2012 17:38
-
-
Save iamdustan/3534716 to your computer and use it in GitHub Desktop.
This file contains 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
// option 1 | |
var Subscription = function (plan) { | |
var self = this; | |
// statics | |
_.each(['dropdown_text full_rate id months name renew_rate special type'].split(' '), | |
function(prop) { this[prop] = ko.observable(plan[prop]); }) | |
this.monthly_rate = ko.computed(function () { | |
return (self.full_rate() / self.months()).toFixed(2); | |
}); | |
}; | |
// option 2 | |
var Subscription = function (plan) { | |
var self = this; | |
this.dropdown_text = ko.observable(plan.dropdown_text); | |
this.full_rate = ko.observable(plan.full_rate); | |
this.id = ko.observable(plan.id); | |
this.months = ko.observable(plan.months); | |
this.name = ko.observable(plan.name); | |
this.renew_rate = ko.observable(plan.renew_rate); | |
this.special = ko.observable(plan.special); | |
this.type = ko.observable(plan.type); | |
this.monthly_rate = ko.computed(function () { | |
return (self.full_rate() / self.months()).toFixed(2); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2 is way better IMO, meta-generated stuff is just annoying to compute in your head