Created
August 21, 2014 11:49
-
-
Save hehongwei44/fe71f10e4d2d9295aeab to your computer and use it in GitHub Desktop.
通过数组,拓展字符串拼接容易导致性能的问题。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function StringBuffer() { | |
this.__strings__ = new Array(); | |
} | |
StringBuffer.prototype.append = function (str) { | |
this.__strings__.push(str); | |
return this; | |
} | |
StringBuffer.prototype.toString = function () { | |
return this.__strings__.join(""); | |
} | |
var buffer = new StringBuffer(); | |
buffer.append("Hello ").append("javascript"); | |
var result = buffer.toString(); | |
alert(result); //Hello javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment