public
Created — forked from Douglasj/gist:1718943

Backbone previous attributes question

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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
});
 
t.change();
 
console.log(t.hasChanged()); // false
 
console.log(t.previousAttributes()); // {var1: 'b', var2: 'b'}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.