Skip to content

Instantly share code, notes, and snippets.

@gf3
Created June 18, 2009 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gf3/132012 to your computer and use it in GitHub Desktop.
Save gf3/132012 to your computer and use it in GitHub Desktop.
Curry method in JavaScript
if (typeof Function.prototype.curry === 'undefined') {
Function.prototype.curry = function() {
var func = this
, a = Array.prototype.slice.call(arguments, 0)
return function () {
var a_len = a.length
, length = arguments.length
while (length--)
a[a_len + length] = arguments[length]
return func.apply(this, a)
}
}
}
// Example 01
function xy (x, y) { return x + y }
var x = xy.curry(7)
x(3) // 10
// Example 02
var warn = alert.curry("Warning!")
warn()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment