Skip to content

Instantly share code, notes, and snippets.

@th507
Last active December 24, 2015 18:19
Show Gist options
  • Save th507/6841704 to your computer and use it in GitHub Desktop.
Save th507/6841704 to your computer and use it in GitHub Desktop.
uncurrying + mixin in JavaScript
// uncurrying and mixin two-in-one
// var a = [1, 2];
// push = factory(Array.prototype.push);
// pushA = factory(Array.prototype.push, a);
// push(a, 3) => a = [1, 2, 3]
// or
// pushA(3) => a = [1, 2, 3]
var call = Function.call;
var slice = Array.prototype.slice;
function factory() {
var defaults = slice.call(arguments);
return function () {
return call.apply(call, defaults.concat(slice.call(arguments)));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment