Snippet usefulness - Function.prototype.call.bind(Function.p

Snippet usefulness - Function.prototype.call.bind(Function.prototype.bind)

本文关键字:Function bind call prototype usefulness Snippet      更新时间:2023-09-26

我看到了一篇关于这个javascript片段的文章:

var binder = Function.prototype.call.bind(Function.prototype.bind);

此片段将: var fBound = f.bind(context);变成: var fBound = binder(f,context);但我想知道它的用处。可以看出,这个片段并没有使代码更短,而是提供了新的函数binder()来取代标准bind(),这使得代码更难阅读,因为程序员需要记住新功能。

你能在这个我可能错过的剪影中提供真正的需求吗?

从博客文章来看,除了句法糖之外,没有"有用性",转:

slice.call([1,2,3], 0, 1);
slice.apply([1,2,3], [0,1]);

slice([1,2,3], 0, 1);

此更改允许将适当的this上下文作为函数的第一个参数传递,而无需显式调用callapply