and*_*rei 6 javascript backbone.js
嗨,有人可以解释为什么在hash()函数中的骨干示例应用程序(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());
},
Run Code Online (Sandbox Code Playgroud)
谢谢 !
#UPDATE
调试器输出
this.without(this.done())
[child, child, child, child]
this.without.apply(this, this.done());
[child, child, child]
Run Code Online (Sandbox Code Playgroud)
关键是在没有写的方式:
function () {
var args = slice.call(arguments);
args.unshift(this.models);
return _[method].apply(_, args);
}
Run Code Online (Sandbox Code Playgroud)
它需要一个可变的参数列表,一种方法是使用 apply:
...
return this.without.apply(this, ['pass', 'these', 'arguments']);
Run Code Online (Sandbox Code Playgroud)
MDN 文档中有更多关于 apply 的信息。
归档时间: |
|
查看次数: |
158 次 |
最近记录: |