JavaScript 学习笔记之Currying技术(转载)

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
原文地址:https://www.cnblogs.com/johnwonder/p/1675249.html