john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

applyf

<!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>

  • « addtwoinvoke
  • curry »

Published

Oct 5, 2013

Category

javascript

~47 words

Tags

  • applyf 1
  • javascript 43