前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【说站】js柯里化函数的好处

【说站】js柯里化函数的好处

作者头像
很酷的站长
发布2022-11-23 15:59:57
2.2K0
发布2022-11-23 15:59:57
举报
文章被收录于专栏:站长的编程笔记

js柯里化函数的好处

好处说明

1、可以把函数式编程变得简洁,没有冗余。

2、尽管有多个参数,仍然可以保留数学函数的定义。

3、可以将函数作为返回值输出,提前返回。

实例

代码语言:javascript
复制
match(/r/g, 'hello world'); // [ 'r' ]
 
const hasLetterR = match(/r/g); // x => x.match(/r/g)
hasLetterR('hello world'); // [ 'r' ]
hasLetterR('just j and s and t etc'); // null
filter(hasLetterR, ['rock and roll', 'smooth jazz']); // ['rock and roll']
 
const removeStringsWithoutRs = filter(hasLetterR); // xs => xs.filter(x => x.match(/r/g))
removeStringsWithoutRs(['rock and roll', 'smooth jazz', 'drum circle']); // ['rock and roll', 'drum circle']
const noVowels = replace(/[aeiou]/ig); // (r,x) => x.replace(/[aeiou]/ig, r)
const censored = noVowels('*'); // x => x.replace(/[aeiou]/ig, '*')
censored('Chocolate Rain'); // 'Ch*c*l*t* R**n'

以上就是js柯里化函数的好处,希望对大家有所帮助。更多js学习指路:js教程

推荐操作环境:windows7系统、jquery3.2.1版本,DELL G3电脑。

收藏 | 0点赞 | 0打赏

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • js柯里化函数的好处
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档