JavaScript有内置的stringbuilder类吗? [英] Does JavaScript have a built in stringbuilder class?
问题描述
我看到一些代码项目解决方案。
但JavaScript中是否有常规实现?
But is there a regular implementation in JavaScript?
推荐答案
如果必须编写代码Internet Explorer确保您选择了一个使用数组连接的实现。使用 +
或 + =
运算符连接字符串在IE上非常慢。对于IE6尤其如此。在现代浏览器上 + =
通常和数组连接一样快。
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("");
请注意 push
方法接受多个参数。
Note that the push
methods accepts multiple arguments.
这篇关于JavaScript有内置的stringbuilder类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!