I currently have a partial-application function which 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 instance:
function foo(x, y)
{
alert(x + y);
}
var bar = foo.curry(1);
bar(2); // alerts "3"
How can I rephrase the curry function to 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); // should alert 6;
Instead of your
curryfunction just use thebindlike: