Created
March 14, 2012 20:49
-
-
Save devth/2039408 to your computer and use it in GitHub Desktop.
Backbone 0.9.0 "previous" weirdness if you override its "change"
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
var Foo = Backbone.Model.extend({ | |
initialize: function() { | |
_.bindAll(this, 'change'); | |
this.bind('change', this.change); | |
}, | |
change: function() { console.log(this.previous('foo'), "to", this.get('foo')) } | |
}); | |
var f = new Foo({foo: 1}); | |
f.set({foo: 2}) | |
// 1 "to" 2 | |
f.set({foo: "hi"}) | |
// 1 "to" "hi" | |
f.set({foo: "33"}) | |
// 1 "to" "33" | |
// The reason for this is because we're overriding `change` up above! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment