I currently have a partial application function that looks like this:
Function.prototype.curry = function() { var args = []; for(var i = 0; i < arguments.length; ++i) args.push(arguments[i]); return function() { for(var i = 0; i < arguments.length; ++i) args.push(arguments[i]); this.apply(window, args); }.bind(this); }
The problem is that it only works for non-member functions, for example:
function foo(x, y) { alert(x + y); } var bar = foo.curry(1); bar(2);
How can I rephrase a curry function that will be applied to member functions, as in:
function Foo() { this.z = 0; this.out = function(x, y) { alert(x + y + this.z); } } var bar = new Foo; bar.z = 3; var foobar = bar.out.curry(1); foobar(2);
bfops source share