我正在按照教程学习backbone.js。我尝试了一些代码,它看起来很奇怪。src
我首先用being初始化了一个模型实例,对模型实例thesource.jpg
做了 a console.log
,然后将src
属性设置为aaa
后跟 a console.log
。
在 javascript 控制台中,我看到两个输出src
的aaa
. 他们不应该不同吗?
JS代码
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);
控制台输出