Skip to content

Instantly share code, notes, and snippets.

@luin
Created May 28, 2013 12:50
Show Gist options
  • Save luin/5662549 to your computer and use it in GitHub Desktop.
Save luin/5662549 to your computer and use it in GitHub Desktop.
JavaScript反柯里化
Function.prototype.unCurrying = function () {
var self = this;
return function () {
var args = Array.prototype.slice.call(arguments);
return self.apply(args[0], args.slice(1));
};
};
var foo = [];
var push = Array.prototype.push.unCurrying();
var slice = Array.prototype.slice.unCurrying();
var join = Array.prototype.join.unCurrying();
push(foo, 'first');
push(foo, 'second');
push(foo, 'third');
console.log(join(foo, ', '));
console.log(foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment