1 var str = "I'm a thirty-five character string.", 2 strs = [], 3 newStr, 4 appends = 5000; 5 6 while (appends--) { 7 strs[strs.length] = str; 8 } 9 10 newStr = strs.join("");
以上代码为了让IE7或者更低版本的浏览器性能更优。其他浏览器使用以下代码:
1 var str = "I'm a thirty-five character string.", 2 newStr = "", 3 appends = 5000; 4 5 while (appends--) { 6 newStr += str; 7 }