场景优化if else
_.cond([ [真值检测函数1,处理器1], [真值检测函数2,处理器2] ]) 加上 pointfree,这个条件处理逻辑高度复用
var _ = require('lodash');
let fn1 = () => { console.log(1); }
let fn2 = () => { console.log(2); }
let fn3 = () => { console.log(3); }
let fn4 = () => { console.log(4); }
let fn = (a) => { console.log('aaa'); }
var func1 = _.cond([
[{ 'geeks': 2, }, fn],
[{ 'geeks': 1, 's': 1 }, fn1],
[{ 'geeks': 1, 's': 2 }, fn2],
[{ 'geeks': 1, 's': 3 }, fn3],
[{ 'geeks': 1, 's': 4 }, fn4],
]);
func1({ 'geeks': 1, 's': 1 })//1
func1({ 'geeks': 2, 's': 2 })//aaa
func1({ 'geeks': 2, })//aaa