<!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);
};
};
}
var addf = applyf( add );
document.writeln( addf(3)(4) ) // 7
document.writeln( applyf(mul)(5)(6) ) // 30
</script></pre></body></html>