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~
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