documentcloud/backbone — Issue #1000: change:attr event fires before all attributes are set
Author: codeboost
Created: 2012-02-14 00:36:25+00:00
State: open

When setting multiple attributes, change fires for every attribute that has changed *while* the model attributes are being changed.

This means that inside the 'change:attr' handler, one has access to a 'half-changed' model, which can be confusing.

Example (CoffeeScript):

model = new Backbone.Model
name: 'Maria'
age: 16

model.bind 'change:name', ->
console.log 'Name is ' + @get('name') + ' and age is ' + @get('age')

model.set
name: 'John'
age: 23

Prints "Name is John and age is 16", which is wrong.

Could you elaborate if this is a design decision or a bug ?