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

Re: Concatenate strings and pass Jslint

Expand Messages
  • Douglas Crockford
    ... var an = []; an.length = n + 1;
    Message 1 of 2 , Aug 2, 2008
    View Source
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "osteocosmosis" <fredistic@...> wrote:
      >
      > To concatenate strings I use:
      >
      > // Concatenation of string 'str', n times.
      > function repeatstr (n, str) {
      > var an = new Array(1 + n);
      > return an.join(str);
      > }
      >
      > ------------
      >
      > This avoids repeated memory allocations that you get from +=, but
      > jslint complains about the 'new Array(1 + n);'
      >
      > So what should I use to concatenate strings?

      var an = [];
      an.length = n + 1;
    Your message has been successfully submitted and would be delivered to recipients shortly.