0
对于缺少引用(上下文)的对象,我有点困惑。箭头函数和bind之间的区别()
在打字稿(与解释原因,某些虚拟参数如下所示):
var x = new SomeClass();
someCallback(function(a){x.doSomething(a)});// some time this x object may
missing the reference (context) of x object
someCallback(a => x.doSomething(a));// if we using arrow function, then how
it manage stabling the object context? which is doing same below bind()code.
bind()的
发箭:从function.bind创建功能()始终保持“这“
var x = new SomeClass();
window.setTimeout(x.someMethod.bind(x), 100);//bind will be also manage
the x context(reference).
问题:
- 它们之间的性能和差异是什么?
- 何时使用
bind()
和arrow(a=>a...)
函数?
这是如何关系到角? – Skeptor
https://stackoverflow.com/questions/22939130/when-should-i-use-arrow-functions-in-ecmascript-6 –
这就是你需要的,简单的谷歌搜索帮助http://2ality.com/2016/ 02/arrow-functions-vs-bind.html –