If you have to write code for Internet Explorer make sure you chose an implementation, which uses array joins. Concatenating strings with the +
or +=
operator are extremely slow on IE. This is especially true for IE6. On modern browsers +=
is usually just as fast as array joins.
When I have to do lots of string concatenations I usually fill an array and don't use a string builder class:
var html = [];
html.push(
"<html>",
"<body>",
"bla bla bla",
"</body>",
"</html>"
);
return html.join("");
Note that the push
methods accepts multiple arguments.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…