javascript函子是什么

说明

1、作为特殊容器通过普通对象实现,该对象具有map方法,map方法可以运行函数处理值(变形关系)。

2、函子是一个持有值的容器,看作普通对象,在其他语言中,可能是一个类。

实例

classContainer{
constructor(value){
this._value=value
}
map(fn){
returnnewContainer(fn(this._value))
}
}
letr=newContainer(str).map(x=>x.toUpperCase())
console.log(r)
原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
Everyone has its disadvantage just like the god bites the apple. the bigger disadvantage you have, the more the god appreciate it.
每个人都会有缺陷,就像被上帝咬过的苹果,有的人缺陷比较大,正是因为上帝特别喜欢他的芬芳
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容