First of all, fixed jsperf http://jsperf.com/bind-vs-emulate/13.
=You should not recreate static functions inside the benchmark. That is not realistic because in real code static functions are only created once.
You can see that var self = this
pattern is still about 60% faster. But it requires the function definition to be inlined where as you can bind from anywhere and therefore have better maintainability.
Well no, the built-in bind semantics are ridiculously convoluted.
When I bind, I just want this:
function bind(fn, ctx) {
return function bound() {
return fn.apply(ctx, arguments);
};
}
If I wanted to pre-apply arguments or use some deep constructor black magic, I would want a totally different function for that. I have no idea why any of this was included in bind.
<rant>Btw, the same problem is with almost anything introduced in ES5, punishing the common case by forcing implementations to handle some theoretical edge case that is not plausibly relevant to anyone in practice. The next language version is continuing on the same path.</rant>
The emulated bind doesn't even try to emulate bind at all. And even if you try to emulate it, you will not be able to do it completely so that's just not fair.
So with everything else equal* the built-in bind cannot be faster than common sense custom bind which just binds.
*In JITs user code has no significant disadvantage to built-in code. In fact both SM and V8 implement many built-ins in Javascript.