reduce的介绍:
最后面那个0代表pre的起始值是0,current代表todos里面每一个元素
let y = this.todos.reduce((pre,current)=>pre+(current.done ? 1:0),0)
还可以用filter写:
this.todos.filter(todo=>todo.done == true).length()
这里是简写:
(pre,current)=>pre+(current.done ? 1:0)
其实等同于:
function(pre,current){
return pre+(current.done ? 1:0);
}