John Resig在Pro Javascript一书中关于Currying的实现代码:

 

// A function that generators a new function for adding numbers
function addGenerator( num ) {

    
// Return a simple function for adding two numbers
    // with the first number borrowed from the generator
    return function( toAdd ) {
        
return num + toAdd
    };

}

// addFive now contains a function that takes one argument,
//
 adds five to it, and returns the resulting number
var addFive = addGenerator( 5 );

// We can see here that the result of the addFive function is 9,
//
 when passed an argument of 4
alert( addFive( 4 ) == 9 );
转自:http://www.cnblogs.com/sanshi/archive/2009/02/17/javascript_currying.html

相关文章:

  • 2021-12-04
  • 2021-10-07
  • 2021-06-09
  • 2021-04-13
  • 2021-10-31
  • 2021-08-30
  • 2021-06-24
猜你喜欢
  • 2021-10-27
  • 2021-12-31
  • 2022-12-23
  • 2022-02-02
  • 2021-07-26
  • 2021-09-07
  • 2021-11-24
相关资源
相似解决方案