<!DOCTYPE html><html><head><title></title></head><body><pre><script>
function add( a , b ) {
return a + b;
}
function mul( a , b ) {
return a * b;
}
function applyf( x ){
return function ( first ) {
return function( second ) // closure means it can access outer variable
{ return x( first , second);
};
};
}
function curry( func, first ){
return function ( second ) {
return func( first , second);
};
}
var add0 = curry( add, 0)
var inc = curry( add, 1)
document.writeln( inc(5) ); // 6
document.writeln( inc( inc( 5 )) ); // 7
var inc = applyf( add, 1);
document.writeln( inc(5) ); // 6
document.writeln( inc( inc( 5 )) ); // 7
var inc = addf( 1);
</script></pre></body></html>