“alert” is not defined when running www.jshint.com

后端 未结 8 1863
长发绾君心
长发绾君心 2020-12-15 02:46

I fixed this by simply adding var alert; However, is this what I should be doing to get the pesky error message to go away? Here is the fix. Here is the fail

8条回答
  •  爱一瞬间的悲伤
    2020-12-15 03:00

    Instead of

    alert('message')
    

    you should use

    window.alert('message');
    

    Because this method is defined in window object.

    This of course assumes you have browser option set to true in your .jshintrc, so this way jshint will know window object is exposed.

    "browser"       : true,     // Standard browser globals e.g. window, document.
    

    *The same thing happens with confirm().

提交回复
热议问题