javascript - Backbone 示例应用程序和 javascript 适用

标签 javascript backbone.js

您好,有人可以解释为什么在 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/

相关文章:

javascript - 跨用户同步主干模型状态的最简单方法是什么? Node .js

javascript - 将 Node 路由与 Backbone 路由绑定(bind)

javascript - 最佳实践 - BackBone JS - 模型 View 关系

javascript - 创建 Wordpress 插件并加载外部脚本

javascript - 如何将值转换为数组

javascript - 二进制搜索以查找最接近目标的数字。未定义为返回值

json - 主干解析 json 响应

javascript - Backbone Collection.add 似乎不起作用

javascript - 将 html 更改为 var

javascript - 如何将 utf-8 数据从 Django 传递到 javascript