Global variables in Javascript and ESLint

后端 未结 2 1344
天涯浪人
天涯浪人 2020-12-02 21:42

I have got multiple javascript files and I have defined some global variable in a file which loads before the others. As a consequence all of the files loaded after the firs

2条回答
  •  一生所求
    2020-12-02 22:18

    You can add globals either per file or in your config. If you don't want to change your config, you'll have to add the used globals in every file.

    To specify globals using a comment inside of your JavaScript file, use the following format:

    /* global var1, var2 */
    

    This defines two global variables, var1 and var2. If you want to optionally specify that these global variables should never be written to (only read), then you can set each with a false flag:

    /* global var1:false, var2:false */
    

    http://eslint.org/docs/2.0.0/user-guide/configuring#specifying-globals

提交回复
热议问题