码迷,mamicode.com
首页 > 其他好文 > 详细

[Ramda] Convert Object Methods into Composable Functions with Ramda

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

标签:pex   into   convert   src   cep   str   logs   color   ast   

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

标签:pex   into   convert   src   cep   str   logs   color   ast   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!