September 23, 2011

partial application in Javascript part 1

I recently recorded a few videos on partial application in JavaScript. In part 1, I explain what it is and I provide a short code snippet as a first draft. I will build upon the code snippet in the subsequent videos.




Here is the code that I am using:
<html>
    <body>
        <script language="javascript">

            Function.prototype.partial = function(){
                var original_function = this;
                var args1 = [].slice.apply(arguments);

                return function(){
                    var args2 = [].slice.call(arguments);
                    return original_function.apply(null, args1.concat(args2));
                };
            };

            function addTwoNumbers(a,b){return a+b;}

        </script>

        Partial application #1

    </body>
</html>


0 comments: