场景优化if else

    _.cond([ [真值检测函数1,处理器1], [真值检测函数2,处理器2] ]) 加上 pointfree,这个条件处理逻辑高度复用

    1. var _ = require('lodash');
    2. let fn1 = () => { console.log(1); }
    3. let fn2 = () => { console.log(2); }
    4. let fn3 = () => { console.log(3); }
    5. let fn4 = () => { console.log(4); }
    6. let fn = (a) => { console.log('aaa'); }
    7. var func1 = _.cond([
    8. [{ 'geeks': 2, }, fn],
    9. [{ 'geeks': 1, 's': 1 }, fn1],
    10. [{ 'geeks': 1, 's': 2 }, fn2],
    11. [{ 'geeks': 1, 's': 3 }, fn3],
    12. [{ 'geeks': 1, 's': 4 }, fn4],
    13. ]);
    14. func1({ 'geeks': 1, 's': 1 })//1
    15. func1({ 'geeks': 2, 's': 2 })//aaa
    16. func1({ 'geeks': 2, })//aaa