syntax with arrow function in TypeScript -


in code in typescript saw

(() => {     const abc = 'blabla';     ... })(); 

what syntax mean ? know arrow functions js - understand this:

() => {     const abc = 'blabla';     ... }); 

but interest of rest of parenthesis ?

ps: original code is

(() => {     const title = 'new document'      newdoc.initialize = () => {         render(             <app title={title} />,             document.queryselector('#contnr')         );     };      render(            <progr />,              document.queryselector('#contnr')     );  })(); 

thank you

in javascript these functions called iife (immediately-invoked function expression), it's definition of function , invoking immediately! for? many reasons...

but, before go reasons, please note arrow functions not part of question, there's not this in example...

also not question not relevant typescript.

few on many reasons:

  • you have scope (by reacting function), without polluting global scope.
  • can can defined "private" functions not accessible outside of iife
  • you in control on what's going in , out of function.

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -