Is it really? You have a click event on a button. If you are able to click that button a thousand times a second, I might see a reason to care about a few clock ticks of performance, but for the use case bind provides an easy readable way to implement event binding.
Oh, I can name you a few times it's worth using bind. Currying, for instance. But you should avoid bind unless you need it. Simply using it to permanently set scope is not a good usage; use an anonymous call (apparently not apply!!) for that.
It is strange that apply is slow; I would think that would be optimized better than call.
function sub_curry(fn /*, variable number of args */) {
var args = [].slice.call(arguments, 1);
return function () {
return fn.apply(this, args.concat(toArray(arguments)));
};
}
It completely agree it is definitely worth using bind to ensure that this is commonly understood and doesn't get lost. If you don't use this, though, you don't need bind.
3
u/[deleted] Mar 09 '15
Thanks for this. All the more reason to avoid bind.