In dem unten, woher kommt b? Ich sehe nicht, dass es weitergegeben wird, also wie könnte es zurückgegeben werden?Makeadder Beispiel von Ben Alman
function lockInFirstArg( fn, a ) {
return function( b ) {
return fn( a, b );
};
}
-Link: http://msdn.microsoft.com/en-us/scriptjunkie/gg575560
Ausführlichere Auszug:
// More-general functions.
function add( a, b ) {
return a + b;
}
function multiply( a, b ) {
return a * b;
}
// Relatively flexible more-specific function generator.
function lockInFirstArg( fn, a ) {
return function( b ) {
return fn( a, b );
};
}
var add1 = lockInFirstArg( add, 1 );
add1( 2 ); // 3
add1( 3 ); // 4
add1( 10 ); // 11
Sie vielleicht einen Blick auf, was currying nehmen wollen, ist: http: //en.wikipedia. org/wiki/Currying – Agos