🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## cond + [link](./cond "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L13161 "View in source.") + [npm](https://www.npmjs.com/package/lodash.cond "See the npm package.") ``` _.cond(pairs) ``` 创建一个函数。 这个函数会遍历 `pairs`,并执行最先返回真值对应的函数,并绑定 `this` 及传入创建函数的参数。 ### 参数 1. pairs (Array) 判断函数对 ### 返回值 (Function) 返回新的函数 ### 示例 ``` var func = _.cond([ [_.matches({ 'a': 1 }), _.constant('matches A')], [_.conforms({ 'b': _.isNumber }), _.constant('matches B')], [_.constant(true), _.constant('no match')] ]); func({ 'a': 1, 'b': 2 }); // => 输出:'matches A' func({ 'a': 0, 'b': 1 }); // => 输出:'matches B' func({ 'a': '1', 'b': '2' }); // => 输出:'no match' ```