【发布时间】:2012-02-04 00:42:09
【问题描述】:
我正在查看 Backbone 待办事项列表,并有一个关于集合的问题。
代码如下:
window.TodoList = Bacbone.Collection.extend({
model: Todo,
localStorage: new Store("todos"),
done: function() {
return this.filter(function(todo){return todo.get("done")})
},
remaining: function() {
return this.without.apply(this, this.done());
}
})
我了解这里发生的一切,除了“剩余”功能。
返回语句:return this.without.apply(this, this.done()); 正在使用下划线方法的代理 - _.without
根据下划线文档,这是为了:
without_.without(array, [*values]) 返回数组的副本 值的所有实例均已删除。 === 用于相等 测试。
_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); => [2, 3, 4]
所以,我知道它是说返回集合中的所有内容,而没有值为 'true' 的 'done' 属性。
我不明白的是链接到它的“应用”功能。这不会出现在 Backbone 文档或 Underscore 文档中。至少在我能找到的任何地方都找不到。
谁能详细解释一下 Return 声明中的这些元素是怎么回事?
【问题讨论】:
标签: javascript jquery backbone.js underscore.js