javascript - JS function problem
黄舟
黄舟 2017-05-19 10:18:18
0
1
401
var filters = {
  all: function (todos) {
    return todos
  },
  active: function (todos) {
    return todos.filter(function (todo) {
      return !todo.completed
    })
  },
  completed: function (todos) {
    return todos.filter(function (todo) {
      return todo.completed
    })
  }
}

filteredTodos: function () {
  return filters[this.visibility](this.todos)
},

I would like to ask how the filteredTodos method calls the filters method to have an array? What is the usage? Please solve your doubts~

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
大家讲道理

filters[this.visibility] This is not an array, but a method under the calling object.

this.visibility的结果可能有三个 all, active, completed So it ends up being something like this:

filters['all'] 就相当于调用了 filters 对象下的 all 方法,因为 this.visibility is a variable, so it must be written like this

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template