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

Concatenate strings and pass Jslint

Expand Messages
  • osteocosmosis
    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); } ...
    Message 1 of 2 , Aug 2 2:04 PM
    • 0 Attachment
      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?
    • Douglas Crockford
      ... var an = []; an.length = n + 1;
      Message 2 of 2 , Aug 2 5:55 PM
      • 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.