0
我目前正在學習骨幹,並試圖包裝我的頭爲什麼需要初始化函數視圖和集合?初始化集合中的屬性
下面是我的一些代碼:
Tasks = Backbone.Collection.extend({
//This is our Task collection and holds our Task models
initialize: function (models, options) {
console.log(options);
this.bind("add", options.view.addTaskListeners);
console.log(this.bind("add", options.view.addTaskListeners));
//Listen for new additions to the collection.
}
});
//master view
AppView = Backbone.View.extend({
el: $("body"),
initialize: function() {
this.tasks = new Tasks(null, { view: this });
// Create a task collection when the view is initialized.
// Pass it a reference to this view to create a connection between the two
},
events: {
"click #add-task": "showPrompt",
},
本教程的創建者決定利用這個「初始化」屬性,但初始化從未用作屬性,如Tasks.initialize或AppView.initialize。我嘗試更改屬性的名稱,但它不起作用。這是一個保留字還是關鍵字?爲什麼需要?謝謝!