My first encounter with .bind() left me puzzled by the fact that the optional arguments passed to the bound function are prepended. This issue arose when I was attempting to delegate tasks to anonymous event handling functions, similar to this:
$('#example').on('change', function(arg1, arg2, evt) {
console.log(evt, arg1, arg2);
}.bind(null, arg1, arg2));
The MDN reference page for .bind() mentions the preppending multiple times but does not explain why. It has left me wondering - why do I need to place arg1
and arg2
before evt
in the function arguments? Wouldn't it be more intuitive and potentially faster if they were appended instead?