1
請說一下,在默認值(如name:'dflt name')上聲明屬性和聲明外部默認屬性(如name:'name支柱')。另外在初始化函數中,當我試圖改變道具值不變時(比如this.name =「Mr。」+ this.name;)。請參閱下面的代碼。骨幹:默認屬性和選項散列中定義的屬性之間的區別
$(document).ready(function(){
arrModel = Backbone.Model.extend({
defaults:{
name:'dflt name'
},
name:'name prop',
initialize:function(){
this.name = "Mr."+this.name;
console.log("init", this.name) // this is printing raj not Mr.raj
}
})
m = new arrModel({
name:'raj',
std:2
});
console.log(m.attributes)
})
感謝比爾艾森豪爾的答案。一票贊成你的善舉:-)。 – rajkamal