💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
## 函数柯里化 应用: 1. 参数复用 ``` function uri_currying (protocol) { return function (hostname, pathname) { return `${protocol}${hostname}${pathname}` } } const uri_https = uri_currying('https://') const uri1 = uri_https('www.baidu.com', '/a.html') const uri2 = uri_https('www.baidu.com', '/b.html') const uri3 = uri_https('www.baidu.com', '/b.html') console.log(uri1, uri2, uri3) ``` 2. 兼容性的使用 ![](https://img.kancloud.cn/90/10/9010307298954cca85e321f77c3367eb_2742x1160.png) 3. **延迟执行** 实现一个这样的 add 函数, 使 add( 1 )( 2 )( 3 ) = 6 add(1 ,2 ,3 )( 4 ) = 10 add( 1 )( 2 )( 3 )( 4 )( 5 ) = 15 ``` function add () { const arg = [...arguments] const inner = function () { arg.push(...arguments) return inner } inner.toString = function () { return arg.reduce((prev, cur) => { return prev + cur }) } return inner } // const sum = add(1, 2) const sum = add(1)(2)(3) console.log(sum) ```