Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 on www.jshint.com.

I'm trying to learn from the error it throws..not necessarily make them go away.

(function () {

"use strict";

var alert;  //  added this in to fix

function initialize_page()
  {
  alert ("hi");
  }

addEventListener('load', initialize_page);

})();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
539 views
Welcome To Ask or Share your Answers For Others

1 Answer

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().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...