2013-12-20 142 views
10

什麼是此JavaScript的TypeScript等效物?TypeScript匿名函數

(function() { 
    /* code here */ 
})(); 

我已經試過這

() => { 
    /* code here */ 
} 

但是,這會產生

(function() { 
    /* code here */ 
}); 

我需要額外的組括號在年底進行匿名函數的執行。

回答

18
(() => { 
    /* code here */ 
})(); 

或簡單地使用JavaScript(這是同樣有效打字稿)

(function() { 
    /* code here */ 
})(); 

...這取決於你是否想用脂肪箭頭捕捉this

Playground