The problem is that you've lost the context of the element. The addEventListener
method has to be called on an element, but you're calling it on a function:
// Here, `this` refers to a function, not an element
return fn.apply(this, args.concat(Array.prototype.slice.call(arguments)));
You would need to pass in the element to your new function. For example:
Function.prototype.curry = function () {
var fn = this,
args = Array.prototype.slice.call(arguments);
return function (context) {
return fn.apply(
context,
args.concat(Array.prototype.slice.call(arguments, 1))
);
};
};
Here's a working example. Notice the addition of a context
argument to the returned function, and also notice the addition of the second argument to the slice
call - that's needed to remove the new context
argument and only apply any following arguments.