Created
November 10, 2011 16:43
-
-
Save jmarnold/1355346 to your computer and use it in GitHub Desktop.
Dependencies in Backbone
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
Model = Backbone.Model.extend({ | |
initialize: function () { | |
this.dependentProperty('y', function () { | |
return this.get('x') * 100; | |
}); | |
} | |
}); |
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
Backbone.Model.prototype.dependentProperty = function (name, evaluator) { | |
this.bind('change', function () { | |
var value = evaluator.call(this); | |
var update = {}; | |
update[name] = value; | |
this.set(update); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you know you really should have blogged this like 2 months ago... it would have saved me countless hours of frustration. :)