How to set 'use strict' globally with JSLint

前端 未结 2 1150
旧巷少年郎
旧巷少年郎 2021-01-12 01:48

I\'m new to javascript and am trying to validate through JSLint. Where should I put \"use strict\" to use it globally and validate?

This gives me error \"Unexpecte

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 02:31

    According to the documentation, the browser option for JSLint automatically disables use of "use strict"; at the global level. As far as I'm aware, there's no way to turn it back on.

    You could turn off the browser option, and get the same predeclared globals as the browser option by using:

    /*global
    Audio, clearInterval, clearTimeout, document, event, history, Image, location, name, navigator, Option, screen, setInterval, setTimeout, XMLHttpRequest
    */
    

    Alternately you could wrap all of your code in an IIFE and use "use strict"; at the top of it.

    Alternately you could switch to JSHint (has more options), and use its strict: global option to allow "use strict"; at global scope.

提交回复
热议问题