Does this type of javascript code go inside jslint?

<script>
  var images = new Array()

  function preload() {
    for (i = 0; i < preload.arguments.length; i++) {
      images[i] = new Image()
      images[i].src = preload.arguments[i]
    }
  }
  preload(
    "https://i.imgur.com/AJDZEOX.jpg",
    "https://i.imgur.com/b3Rqi4d.png",
    "https://i.imgur.com/96Q10GA.png",
    "https://i.imgur.com/WzHsnG7.png",
    "https://i.imgur.com/CzqEXBq.jpg",
    "https://i.imgur.com/fOfpsiC.png",
    "https://i.imgur.com/b3Rqi4d.png"
  )

</script>

What does this mean?

If you use this solution, don’t forget the var statement for the i-variable. Otherwise it will be set globally which can cause error that are really hard to solve (unless you know that you forgot the var statement. for (var i = 0.....

Also, how do you put this into jslint?

  var images = new Array()

  function preload() {
    for (i = 0; i < preload.arguments.length; i++) {
      images[i] = new Image()
      images[i].src = preload.arguments[i]
    }
  }
  preload(

  )

I just fixed it:

How do you put this into jslint?

Putting it into jslint isn’t working for me.

Is there a specific way it would go in?

<script>
var images = [];
function preload() {
    for (var i = 0; i < arguments.length; i++) {
        images[i] = new Image();
        images[i].src = preload.arguments[i];
    }
}

 preload(
    "https://i.imgur.com/AJDZEOX.jpg",
    "https://i.imgur.com/b3Rqi4d.png",
    "https://i.imgur.com/96Q10GA.png",
    "https://i.imgur.com/WzHsnG7.png",
    "https://i.imgur.com/CzqEXBq.jpg",
    "https://i.imgur.com/fOfpsiC.png",
    "https://i.imgur.com/b3Rqi4d.png"
  )
</script>

This code works better:

What’s it about this code that makes it seem like it works really well?

It’s not a lot of code, simple and does what it’s supposed to do.


  <script>
  if (document.images) {
    img1 = new Image();
    img1.src = "https://i.imgur.com/AJDZEOX.jpg";
    img2 = new Image();
    img2.src = "https://i.imgur.com/UzRn6Qx.png";
    img3 = new Image();
    img3.src = "https://i.imgur.com/96Q10GA.png";
    img4 = new Image();
    img4.src = "https://i.imgur.com/WzHsnG7.png";
    img5 = new Image();
    img5.src = "https://i.imgur.com/CzqEXBq.jpg";
    img6 = new Image();
    img6.src = "https://i.imgur.com/fOfpsiC.png";
    img7 = new Image();
    img7src = "https://i.imgur.com/b3Rqi4d.png";
  }
</script>

Do these type of scripts go inside jslint?

<script>
  if (document.images) {
    img1 = new Image();
    img1.src = "";
  }
</script>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.