函子

2020-07-15  本文已影响0人  罗不错
function Container(val){
        this.value = val
     }
     Container.of=function(value){
       return new Container(value)
     }
     Container.prototype.map =function(fn){
       return Container.of(fn(this.value))
     }
     let double = x=>x*2
     let startFn =function(val){
          val++
          return  Container.of(val)
     }
     let obj = startFn(3).map(double).map(double)
     console.log(obj)
上一篇 下一篇

猜你喜欢

热点阅读