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

2976Re: [jslint] Re: Array construction bug

Expand Messages
  • Joe Hansche
    Aug 31, 2012
      According to MDN that is not what actually happens:
      https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/length

      You can only truncate an array's length. Artificially increasing an array's
      "length" still serves no purpose if you don't initialize what's *in* it.
      On Aug 31, 2012 3:59 AM, "Alexandre Morgaut" <morgaut@...> wrote:

      > **
      >
      >
      > Yes there is a workaround, one that still respect JSLint guidelines
      >
      > You can fix the length without the array constructor, even with a dynamic
      > value
      >
      > Just do:
      >
      > var len = 50;
      > var arr = [];
      > arr.length = len;
      >
      > --- In jslint_com@yahoogroups.com, Martin Cooper <mfncooper@...> wrote:
      > >
      > > If I need to create an array with a specified length, and the length
      > > is a literal, JSLint is happy enough with this:
      > >
      > > var arr = new Array(50);
      > >
      > > If, however, the value comes from a variable:
      > >
      > > var len = 50,
      > > arr = new Array(len);
      > >
      > > JSLint complains with an unusable "solution", despite the value being a
      > Number:
      > >
      > > Use the array literal notation [].
      > >
      > > Of course, if I use array literal notation, I don't get the semantics I
      > want.
      > >
      > > Seems like a bug to me. Is there a workaround?
      > >
      >
      >
      >


      [Non-text portions of this message have been removed]
    • Show all 21 messages in this topic