Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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