4 ms·
AFAICT Closures are still much faster than Function.prototype.bind. (http://jsperf.com/bind-vs-closure-setup/44 http://jsperf.com/bind-vs-closure-setup/44) Co
by Lio 11y ago
AFAICT Closures are still much faster than Function.prototype.bind.
(http://jsperf.com/bind-vs-closure-setup/44 http://jsperf.com/bind-vs-closure-setup/44)
Could anyone who knows more about the implementation details point to an explanation of what's going on under the surface?
- draw_down 11y agoHow could test1 here ever be faster than test2? The functions are identical but calling test1 will always incur twice the actual function invocations, first to the bound function and then to _test1.
- inglor 11y agoHere is an answer I wrote about it a while back http://stackoverflow.com/questions/17638305/why-is-bind-slower-than-a-closure http://stackoverflow.com/questions/17638305/why-is-bind-slow... Let me know if you have any questions about it
- Lio 11y agoThat's a great answer, thank you.
- songgao 11y agoIn case you are interested, `Function.prototype.bind` in V8 is implemented here: https://github.com/nodejs/node/blob/9fddd83cf9adf505bce2e2373881df0c4d41b261/deps/v8/src/v8natives.js#L1763 https://github.com/nodejs/node/blob/9fddd83cf9adf505bce2e237... https://github.com/nodejs/node/blob/9fddd83cf9adf505bce2e2373881df0c4d41b261/deps/v8/src/v8natives.js#L1659 https://github.com/nodejs/node/blob/9fddd83cf9adf505bce2e237...
- Lio 11y agoThat's vert interesting. Thank you.