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)
},
很想问一下filteredTodos这个方法调用filters方法怎么有数组呢?这是什么用法呢?求解惑~
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
filters[this.visibility]这里不是数组,是调用对象下的方法。this.visibility的结果可能有三个all,active,completed所以最终是个类似于这样的东西:filters['all']就相当于调用了filters对象下的all方法,因为this.visibility是个变量,所以必须写成这种写法