Backbone のスコープについて説明してもらえますか? 以下の例で get メソッドを使用してデフォルト変数の値を取得する最良の方法はどれですか?
get メソッドを使用しないと、配列が未定義になります。
App.Models.Site = Backbone.Model.extend({
defaults: {
testArray: [1, 2, 3]
},
initialize: function(){
console.log('initialize', this.testArray); // logs undefined
console.log('initialize', this.get('testArray')); // logs [1, 2, 3]
this.test();
},
test: function(){
console.log('initialize', this.testArray); // logs undefined
console.log('test', this.get('testArray')); // logs [1, 2, 3]
}
});