Loading ...
Sorry, an error occurred while loading the content.

Two ideas for defect tests for jslint

Expand Messages
  • James Clark
    Here are two javascript mistakes I have recently made which jslint might be able to check for: 1. using the same variable in two nested loops var i; for (i =
    Message 1 of 1 , Jan 21, 2009
    • 0 Attachment
      Here are two javascript mistakes I have recently made which jslint might
      be able to check for:


      1. using the same variable in two nested loops

      var i;
      for (i = 0; i < 10; i ++) {
      for (i = 0; i < 5; i ++) {
      }
      }

      The above example results in an infinite loop, and obviously I intended
      to create a second variable for the inner loop. It seems to me that
      re-using a variable like this would rarely be useful, and would
      generally be bad coding style. I wonder if jslint could detect this
      scenario?


      2. using the 'delete' operation on an HTMLElement

      var x = document.getElementById("x");
      x.my_attribute = 10;
      delete x.my_attribute;

      This causes the error 'Object doesn't support this action' in IE6.
      jslint obviously cannot detect all instances of this defect, since it
      can't always know whether a variable is an HTMLElement. I wonder if
      jslint might find some of these though? For example, if a variable was
      assigned to the result of document.getElementById then until it is
      re-assigned you must not call delete on one of it's attributes?


      -jamie
    Your message has been successfully submitted and would be delivered to recipients shortly.