Snippet usefulness - Function.prototype.call.bind(Function.p
Snippet usefulness - Function.prototype.call.bind(Function.prototype.bind)
我看到了一篇关于这个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
上下文作为函数的第一个参数传递,而无需显式调用call
和apply
。
相关文章:
- 直接在函数声明上使用function.prototype.bind
- requestAnimationFrame的Function.prototype.bind导致属性不可读
- 函数式编程 - .bind.apply for curry function.
- 使用 function.bind 将函数绑定到此函数
- Snippet usefulness - Function.prototype.call.bind(Function.p
- 使用 Function.prototype.bind.apply(Obj, args) 将参数传递给对象,只传递第一个元
- 函数(){}.bind(this) 和 angular.bind(this, function() {}) 之间的区别
- 尝试在node.js上模拟function.bind()
- Function.prototype.call.bind 是如何工作的
- 使用 Function.prototype.bind 或保存的引用
- bind() on promise error function - javascript
- Phantomjs Function.prototype.bind
- Function.prototype.bind with null 作为参数
- Python alternative to Javascript function.bind()?
- What does "Function.call.bind(Function.bind)" mean
- 如何理解“{ fun: function.bind(this) }”
- 为什么Function.bind("foo").call("bar")总是将th
- 我如何在this.function.bind(this)中替换任何数值作为参数
- Function.bind.bind(Function.call)是如何解调的?
- Javascript中的Function.bind与Closure:如何选择