我很難理解Backbone.js中的Todo.js教程中提到的「this」是什麼。具體而言,在裏面APPVIEW:Todo.js中提到的關鍵字是什麼? (骨幹教程)
initialize: function() {
this.input = this.$("#new-todo");
this.allCheckbox = this.$("#toggle-all")[0];
Todos.bind('add', this.addOne, this);
Todos.bind('reset', this.addAll, this);
Todos.bind('all', this.render, this);
this.footer = this.$('footer');
this.main = $('#main');
},
所以當Todos.bind( '添加',this.addOne,這一點)被調用時,它被認爲(this.addOne)綁定到集合( '添加' )。如果是這樣,我們假設第三個參數(「this」)也引用了AppView對象。爲什麼我們需要將「this」作爲第三個參數?
註釋源代碼:http://backbonejs.org/docs/todos.html
謝謝你的澄清。非常感激。還有一個問題,如果我可能:在源代碼中,對於AppView中的addOne函數,參數「todo」是指什麼? – Sean
@SeanDokko它是對一個實例化的TodoList集合的引用。 – alex
但是不會有衝突,因爲TodoList不是一個模型,而是一個集合?這不是更有意義嗎: 模型:新模型而不是模型:待辦事項? – Sean