以前从未见过.apply方法。有人可以向我解释它的作用吗?这是从http://addyosmani.github.com/backbone-fundamentals/应用程序到底做了什么?
var app = app || {};
var TodoList = Backbone.Collection.extend({
model: app.Todo,
localStorage: new Backbone.LocalStorage(’todos-backbone’),
completed: function() {
return this.filter(function(todo) {
return todo.get(’completed’);
});
},
remaining: function() {
return this.without.apply(this, this.completed());
},
nextOrder: function() {
if (!this.length) {
return 1;
}
return this.last().get(’order’) + 1; },
comparator: function(todo) {
return todo.get(’order’);
}
});
app.Todos = new TodoList();
看看这里:https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/apply – Blender
它可以让你改变'this'的上下文并且传递一个数组作为参数。 – elclanrs