Why embed the JavaScript class in an anonymous function() call?

前端 未结 6 569
北恋
北恋 2021-02-05 10:31

I was reading about the new JavaScript-like language from Microsoft called TypeScript. In the playground (example section), there is a simple class in TypeScript syntax converte

6条回答
  •  后悔当初
    2021-02-05 10:39

    Besides the obvious scoping/closure reasoning. Using an anonymous function that invokes itself immediately pre-loads (interprets) the class definition. This allows any JIT optimizations to be front loaded within the execution. In short, for larger more complex applications it will improve performance.

提交回复
热议问题