您好,有人可以解释为什么在 remaining() 函数中的 Backbone 示例应用程序 ( http://backbonejs.org/examples/todos/index.html ) 中,使用 apply (this.without.apply(this, this.done( ));) 而不是 this.without(this.done())
// Filter down the list of all todo items that are finished.
done: function() {
return this.where({done: true});
},
// Filter down the list to only todo items that are still not finished.
remaining: function() {
return this.without.apply(this, this.done());
},
谢谢!
#更新
调试器输出
this.without(this.done())
[child, child, child, child]
this.without.apply(this, this.done());
[child, child, child]
最佳答案
可变参数列表
关键是在路上没有写:
function () {
var args = slice.call(arguments);
args.unshift(this.models);
return _[method].apply(_, args);
}
它期待一个可变的参数列表,一种方法是使用 apply:
...
return this.without.apply(this, ['pass', 'these', 'arguments']);
在 MDN documentation 中有更多关于申请的信息.
关于javascript - Backbone 示例应用程序和 javascript 适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753680/