🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 科里化 curry 的概念很简单:只传递给函数一部分参数来调用它,让它返回一个函数去处理剩下的参数 ## 实例 hello world ``` var add = function(x) { return function(y) { return x + y; }; }; var increment = add(1); var addTen = add(10); increment(2); // 3 addTen(2); // 12 ``` 匹配字符串 ``` var curry = require('lodash').curry; var match = curry(function(what, str) { return str.match(what); }); //方式一 match(/\s+/g, "hello world"); // 方式二 var hasSpaces = match(/\s+/g); // function(x) { return x.match(/\s+/g) } hasSpaces("hello world"); ``` 这里表明的是一种“预加载”函数的能力, ## 练习题 > [练习题](https://llh911001.gitbooks.io/mostly-adequate-guide-chinese/content/ch4.html#%E4%B8%8D%E4%BB%85%E4%BB%85%E6%98%AF%E5%8F%8C%E5%85%B3%E8%AF%AD%E5%92%96%E5%96%B1)