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

前端 未结 6 568
北恋
北恋 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:37

    The anonymous function is probably there to prevent name collition with other parts of the code. Think of it this way, inside your anonymous function, you could even declare a variable called "$" to be whatever you want, and at the same time, be using jQuery on other parts of your code without conflict.

提交回复
热议问题