Google News
logo
Backbone - Interview Questions
Give an example to demonstrate how can you see the changes on a single attribute of a model?
Whenever you change some data within the model, the model objects fire the "change" event. However, the object fires another event with a name specific to the change attribute : "change:[attribute]".
 
For example :
 
var Fruit = Backbone.Model.extend({})  
var fruit = new Fruit({  
    weight: 3.25  
})  
fruit.on('change:weight, function() {  
    // Event "change:weight" will fire whenever the weight attribute of fruit changes.  
})​

 

 
Advertisement