Currying function arguments is the process of pre-defining arguments within a functor (a function that returns a function). A simple way to achieve this in JavaScript or ActionScript 2 is to extends the Function object:

(in ActionScript 2, the Function class isn’t directly available – you’ll need to change


Often, currying is exampled as a support structure for math-heavy applications. A simple example might look like this:

Which – obviously – returns the product of argument a times argument b.

If you have a heavily-used variable that you want to use often, you can curry it to the multiplyBy function. For example, if you have a particular tax rate determined by the user’s state, you could curry it like so:

then whenever you need to get the price of anything plus tax, you’d just call

While this is certainly handy, I think currying is still heavily underused, even for DOM-heavy applications. An under-appreciated facet of currying using the prototyped method offered above is scope preservation – the returned function is always called from “this”, so is very handily used as event handlers. Consider the following basic function:

A simple function to set style properties based on an Object’s key:value pairs. By using Function.prototype.bind, we can use this as an event handler for arbitrary elements:

You can also define functions with specific parameters for a callback without the opacity of nested anonymous functions:

Since Function objects are rarely extended or expandoed, this technique is fairly safe from the potential iterative collisions we’re warned of by those who argue against extending prototypes at all.

There are many more uses, and many far more sophisticated than these, but (IMHO) this behavior is common enough and desirable enough that it should have been included (or should I say… should be included?) in core ECMA methods.