<!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 addf( first )
{
return function( second ) // closure means it can access outer variable
{
return first + second;
};
}
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);
};
}
function twice( binary ){
return function( a ){
return binary( a, a );
};
}
function sub( first, second) { return first - second; }
function switcheroo( func )
{
return function( first, second ){
return func( second, first );
}
}
/*
function switcheroogen( func )
{
return function( ...args ){
return func(...(args.reverse() );
}
}
*/
var bus = switcheroo(sub)
document.writeln( bus(3,2) ); // -1
</script></pre></body></html>