Currying in JavaScript
Written by on February 27th, 2007 in Ajax News.
Dustin Diaz has a nice entry on currying in JavaScript a technique used often in languages such as LISP, Perl, and many others.
Dustin’s curry implementation:
JAVASCRIPT:
-
-
function curry (fn, scope) {
-
var scope = scope || window;
-
var args = [];
-
for (var i=2, len = arguments.length; i <len; ++i) {
-
args.push(arguments[i]);
-
};
-
return function() {
-
fn.apply(scope, args);
-
};
-
}
-
This should look somewhat similar to Prototype bind and of course Dojo has dojo.lang.curry() which we mentioned awhile ago.
Source: Ajaxian
Original Article: http://ajaxian.com/archives/currying-in-javascript