7 ms·
So is it .bind() itself that is slow, or the function that it returns? Assuming the bind operation itself is done during initialization, its slowness is pretty
by cjfont 13y ago
So is it .bind() itself that is slow, or the function that it returns? Assuming the bind operation itself is done during initialization, its slowness is pretty irrelevant.
- kevingadd 13y agoBind itself is slower than doing it by hand with a closure, and the return value is an order of magnitude slower than the hand-written closure and pollutes type information for your entire application, making all your code slower.
- rtpg 13y agowhy not use a "JS-native"implemtation then? Are there some issues with the spec that need to be respected?
- kevingadd 13y agoI'm not aware of any good reason to use Function.bind. Presumably at some point in the future VMs could optimize it such that it would be faster than a native JS polyfill, but right now the polyfill is superior. If you just want to slam out some JS one-liners, though, you obviously want to use built-in functions where possible.