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

Categories

0 votes
569 views
in Technique[技术] by (71.8m points)

javascript - "alert" is not defined when running www.jshint.com

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

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

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...