箭头函数
特点:没有this arguments prototype ,没有就向上找
1 | // node中没有window 代码在浏览器中执行 |
面试题:
1 | // 1. |
不能再扩展原型
1 | const fn = ()=>{} |
数组
forEach filter map find findIndex some every reduce
some & every
1 | //some() 方法测试数组中是不是有元素通过了被提供的函数测试。它返回的是一个Boolean类型的值。 |
reduce
1 | [1,2,3,4,5].reduce((pre, curr, index, arr)=>{ |
示例 收敛
1
2
3
4 let total = [{price: 1, count: 5}, {price: 2, count: 5}, {price: 3, count: 6}].reduce( (acc, curr, index, arr) => {
return acc + curr.price * curr.count;
}, 0); // 这里这个0就代表初始值 即第一项
console.log(total); // 33
示例 数组扁平化
1 | let arr = [1,[2,[3,[4,[5]]]]]; |
https://stackoverflow.com/questions/50993498/flat-is-not-a-function-whats-wrong
示例 函数的组合 compose (redux源码)
1 | function sum(a,b){ |
上面的写法是因为知道有reduceRight 可以反向 现在正向来写
1 | function sum(a,b){ |
compose 组合多个函数 这个是redux compose的原理
作业
1 | 1.反柯里化 |