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 分享