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

374Re: "Use the array literal notation []."

Expand Messages
  • Noah Peters
    Jan 30, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, James Clark <sbj@...> wrote:
      >
      > Douglas Crockford wrote:
      > >
      > >
      > > --- In jslint_com@yahoogroups.com
      <mailto:jslint_com%40yahoogroups.com>,
      > > James Clark <sbj@> wrote:
      > > >
      > > > Part of my project uses a statement like the following:
      > > >
      > > > var b = new Array(a.length);
      > > >
      > > > but jslint complains:
      > > >
      > > > Use the array literal notation [].
      > >
      > > If you can demonstrate a significant performance advantage, then I
      > > will relax the test. Stylistically, I think [] is better, but I will
      > > bow to a compelling performance argument.
      >
      > I did a little experimenting and web-searching. I have found nothing
      > conclusive, but some quickly-thrown-together tests found no significant
      > difference in performance. So for now I will simply initialize the
      > array with [].
      >
      > -jamie
      >

      This is just an example implementation, but is probably representative
      of how Arrays are implemented in other JavaScript libraries.

      http://blogs.msdn.com/jscript/archive/2008/04/08/performance-optimization-of-arrays-part-ii.aspx

      But, basically JavaScript arrays are sparse and not dense arrays,
      therefore the array memory is not pre-allocated.

      -noah
    • Show all 5 messages in this topic