zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[Ramda] Convert Object Methods into Composable Functions with Ramda

with object INTO convert Functions methods Ramda
2023-09-14 09:00:52 时间

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')