首页 > 其他 > 详细

[Ramda] Convert Object Methods into Composable Functions with Ramda

时间:2017-03-07 16:44:04      阅读:152      评论:0      收藏:0      [点我收藏+]

In this lesson, we‘ll look at how we can use Ramda‘s invoker and constructNfunctions to take methods of an object and turn them into reusable utility functions that are curried and accept their object as the last argument. We‘ll convert a dot-chained string of jQuery methods and create a composed function that can be applied to multiple elements.

 

      const {invoker, compose, constructN} = R

      // $(‘#sample‘)
      //   .animate({left:‘250px‘})
      //   .animate({left:‘10px‘})
      //   .slideUp()
      
      const animate = invoker(1, animate)
      const slide = invoker(0, slideUp)
      const jq = constructN(1, $)
      
      const animateDiv = compose(
        slide, 
        animate({left:10px}), 
        animate({left:250px}),
        jq
        )
      
      animateDiv(#sample)
      animateDiv(#sample2)

 

 

[Ramda] Convert Object Methods into Composable Functions with Ramda

原文:http://www.cnblogs.com/Answer1215/p/6515398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!