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

371"Use the array literal notation []."

Expand Messages
  • James Clark
    Jan 30, 2009
    • 0 Attachment
      Part of my project uses a statement like the following:

      var b = new Array(a.length);

      but jslint complains:

      Use the array literal notation [].

      My theory here is that it is better to start the array with the length
      already initialized, rather than create an empty one and push the
      elements on later. Depending on how the javascript interpreter is
      implemented, this might be faster.

      I'm not exactly sure why using the Array constructor would be bad,
      except possibly because someone else might have redefined it. So in
      that case should I be writing this?

      var b = [].constructor(a.length);

      Or is my assumption about performance incorrect?

      -jamie
    • Show all 5 messages in this topic