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 –