zoukankan      html  css  js  c++  java
  • [Ramda] Convert Object Methods into Composable Functions with Ramda

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

  • 相关阅读:
    Django cache (缓存)
    Django CSRF
    Django 中的 Cookie 和 Session
    Django views 中的装饰器
    Ajax 基础
    JavaScript 对象
    Django ORM 操作
    Django 视图
    Django 路由系统
    Django 模版语言
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6515398.html
Copyright © 2011-2022 走看看