How to declare global variables when using the strict mode pragma

前端 未结 5 1452
梦如初夏
梦如初夏 2021-01-31 16:52

It\'s considered good practice to use a self-invoking function to wrap strict mode compliant code, often called the strict mode pragma:

(function(){
  \"use stri         


        
5条回答
  •  执笔经年
    2021-01-31 17:16

    Method 1 would fail if it's pasted in another function.

    Using method 3, it is easier to export your methods to another namespace. Simply replacing window with, say, frames[0] or document is enough to attach all methods to a custom namespace.

    I recommend method 3, for the last reason.

提交回复
热议问题