Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Backbone previous attributes question
var Backbone = require('backbone'),
M = Backbone.Model.extend(),
t = new M({
var1: 'a',
var2: 'b'
console.log(t.toJSON()); // {var1: 'a', var2: 'b'}
t.set({ var1: 'b' }, {silent: true});
console.log(t.hasChanged()); // true
console.log(t.previousAttributes()); // {var1: 'a', var2: 'b'}
console.log(t.changedAttributes()); // {var1: 'b'}
t.on('change', function() {
console.log(t.hasChanged('var1')); // true
console.log(t.hasChanged()); // false
console.log(t.previousAttributes()); // {var1: 'b', var2: 'b'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment