Skip to content

Instantly share code, notes, and snippets.

@iamdustan
Created August 30, 2012 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamdustan/3534716 to your computer and use it in GitHub Desktop.
Save iamdustan/3534716 to your computer and use it in GitHub Desktop.
// 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);
});
};
@tj
Copy link

tj commented Aug 30, 2012

2 is way better IMO, meta-generated stuff is just annoying to compute in your head

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment