File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 7
7
< body >
8
8
< script >
9
9
/* Title: append
10
- * Description: use string concatenate and set innerHTML
10
+ * Description: use string concatenate and set innerHTML. Note that it is recommended to use the
11
+ * array.join technique to concatenate long strings.
11
12
*/
12
13
13
14
// antipattern
34
35
} ) ;
35
36
$ ( '#ballers' ) . html ( myhtml ) ;
36
37
38
+ // concatenate very long strings
39
+ var myHtmlBuffer = [ ] ;
40
+ $ . each ( reallyLongArray , function ( count , item ) {
41
+ myHtmlBuffer . push ( '<li>' + item + '</li>' ) ;
42
+ } ) ;
43
+ $ ( '#ballers' ) . html ( myHtmlBuffer . join ( '' ) ) ;
37
44
38
45
// References
39
46
// http://paulirish.com/2009/perf/
47
+ // http://www.sitepen.com/blog/2008/05/09/string-performance-an-analysis/
48
+ // http://stackoverflow.com/questions/112158/javascript-string-concatenation
49
+ // http://stackoverflow.com/questions/153381/javascript-string-concatenation-faster-than-this-example
40
50
</ script >
41
51
</ body >
42
- </ html >
52
+ </ html >
You can’t perform that action at this time.
0 commit comments