1

I used this answer https://stackoverflow.com/a/5224638/7346441 to check if an external website is either online or not. And it works just fine.

But when I run JShint I get the W030 message on line 5 and 8:

function ifServerOnline(ifOnline, ifOffline) {
    if ($('span#OfflineCheckClass').length > 0 && $('span#OfflineCheckerURL').length > 0) {

        var img = document.body.appendChild(document.createElement('img'));
        img.onload = function () {
            ifOnline && ifOnline.constructor === Function && ifOnline();
        };
        img.onerror = function () {
            ifOffline && ifOffline.constructor === Function && ifOffline(); 
        };
        img.src = $('#OfflineCheckerURL')[0].innerHTML;
    }
}

and the function:

ifServerOnline(function () {
    // just continue
},
function () {
    var offlineMessageClass = $('#OfflineCheckClass')[0].innerHTML;
    var offlineTekst = document.getElementsByClassName(offlineMessageClass);
    offlineTekst[0].innerHTML = $('span#OfflineCheckerTekst')[0].innerHTML;
});

What is wrong?

Community
  • 1
  • 1
user14947
  • 11
  • 3

1 Answers1

1

JSHint doesn't like expression statements like

    ifOnline && ifOnline.constructor === Function && ifOnline();

If you wanted to make the thing happy, you could change that to

  if (ifOnline && ifOnline.constructor === Function) {
    ifOnline();
  }
Pointy
  • 405,095
  • 59
  • 585
  • 614