Skip to content

Instantly share code, notes, and snippets.

@devth
Created March 14, 2012 20:49
Show Gist options
  • Save devth/2039408 to your computer and use it in GitHub Desktop.
Save devth/2039408 to your computer and use it in GitHub Desktop.
Backbone 0.9.0 "previous" weirdness if you override its "change"
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