【说站】js柯里化函数的好处
js柯里化函数的好处
好处说明
1、可以把函数式编程变得简洁,没有冗余。
2、尽管有多个参数,仍然可以保留数学函数的定义。
3、可以将函数作为返回值输出,提前返回。
实例
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电脑。
本站发布的内容若侵犯到您的权益,请邮件联系站长删除,我们将及时处理!
从您进入本站开始,已表示您已同意接受本站【免责声明】中的一切条款!
本站大部分下载资源收集于网络,不保证其完整性以及安全性,请下载后自行研究。
本站资源仅供学习和交流使用,版权归原作者所有,请勿商业运营、违法使用和传播!请在下载后24小时之内自觉删除。
若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,使用者自行承担,概与本站无关。