You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple bind, faster than native
*/
function bind (fn, ctx) {
function boundFn (a) {
const l = arguments.length;
return l
? l > 1
? fn.apply(ctx, arguments)
: fn.call(ctx, a)
: fn.call(ctx)
}
// record original fn length
boundFn._length = fn.length;
return boundFn
}
The "bind is slow" myth has not been true for quite some time. Native bind should be faster on any any much recent browser. And arrow functions should be even faster as long as there is no need to reuse these functions somewhere else.
What problem does this feature solve?
There is a helper function bundled in Vue.js:
/**
*/
function bind (fn, ctx) {
function boundFn (a) {
const l = arguments.length;
return l
? l > 1
? fn.apply(ctx, arguments)
: fn.call(ctx, a)
: fn.call(ctx)
}
// record original fn length
boundFn._length = fn.length;
return boundFn
}
The "bind is slow" myth has not been true for quite some time. Native bind should be faster on any any much recent browser. And arrow functions should be even faster as long as there is no need to reuse these functions somewhere else.
Please refer to the benchmark https://jsperf.com/bind-is-slow
I think there should be a bigger review of other helper functions, to see if the case for their use is still there in modern browses.
What does the proposed API look like?
Can we replace "simple bind" with native bind?
The text was updated successfully, but these errors were encountered: