Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript anonymous function

What is the TypeScript equivalent of this JavaScript?

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

I have tried this

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

But this produces

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

I need the extra set of parenthesis at the end to perform an execution of the anonymous function.

like image 889
Matthew Layton Avatar asked Dec 20 '13 09:12

Matthew Layton


1 Answers

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

or simply use the JavaScript (which is equally valid TypeScript)

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

... depending whether you want to capture this using the fat arrow.

Playground.

like image 106
Jude Fisher Avatar answered Sep 28 '22 04:09

Jude Fisher