I am learning backbone.js by following a tutorial. I tried out some code, and it appeared really strange. I first initialized a model instance with src being thesource.jpg, did a console.log of the model instance, then set the src attribute to aaa followed by a console.log.
In the javascript console, I see that for both outputs, the src is the same aaa. Shouldnt they be different?
JS Code
var Photo = Backbone.Model.extend({
defaults: {
src: 'placeholder.jpg',
title: 'An image placeholder',
coordinates: [0, 0]
},
initialize: function() {
this.bind("change:src", function() {
var src = this.get("src");
console.log('Image source updated to ' + src);
});
console.log('This model has been initialized!');
},
changeSrc: function(source) {
this.set({src: source});
}
});
window.myPhoto = new Photo({title: "My awesomeness",
src: "thesource.jpg",
location: "Boston",
tags: ['big game', 'vacation']});
console.log(myPhoto.attributes);
myPhoto.set({src:'aaaa'});
console.log(myPhoto.attributes);
Console Output
