Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created November 10, 2011 16:43
Show Gist options
  • Save jmarnold/1355346 to your computer and use it in GitHub Desktop.
Save jmarnold/1355346 to your computer and use it in GitHub Desktop.
Dependencies in Backbone
Model = Backbone.Model.extend({
initialize: function () {
this.dependentProperty('y', function () {
return this.get('x') * 100;
});
}
});
Backbone.Model.prototype.dependentProperty = function (name, evaluator) {
this.bind('change', function () {
var value = evaluator.call(this);
var update = {};
update[name] = value;
this.set(update);
});
};
@mxriverlynn
Copy link

you know you really should have blogged this like 2 months ago... it would have saved me countless hours of frustration. :)

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