Skip to content

Instantly share code, notes, and snippets.

@w495
Created December 11, 2013 02:03
Show Gist options
  • Save w495/7903994 to your computer and use it in GitHub Desktop.
Save w495/7903994 to your computer and use it in GitHub Desktop.
add(1)(2)(3) // 6
'use strict'; // Luke
// -------------------------------------------------
// Просто
// -------------------------------------------------
var add = function(x) {
var temp = x;
var f = function (y) {
temp += y;
return f;
};
f.valueOf = function () { return temp; };
return f;
}
// -------------------------------------------------
// Сложно
// -------------------------------------------------
Function.prototype.curry = function() {
if (!arguments.length)
return this;
var fn = this;
var cached = arguments[0];
return function() {
return fn.apply(
this,
[cached].concat([arguments[0]])
);
}
};
var addc = function(x) {
return (function (x, y) { return x + y }).curry(x)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment