accomplish:
function StringBuffer() { this.__strings__ = []; }; StringBuffer.prototype.Append = function (str) { this.__strings__.push(str); return this; }; //Format string StringBuffer.prototype.AppendFormat = function (str) { for (var i = 1; i < arguments.length; i++) { var parent = "//{" + (i - 1) + "//}"; var reg = new RegExp(parent, "g") str = str.replace(reg, arguments[i]); } this.__strings__.push(str); return this; } StringBuffer.prototype.ToString = function () { return this.__strings__.join(''); }; StringBuffer.prototype.clear = function () { this.__strings__ = []; } StringBuffer.prototype.size = function () { return this.__strings__.length; }Instantiated calls
var sbHtml=new StringBuffer(); sbHtml.Append('hello'); sbHtml.Append('world'); console.log(sbHtml.ToString());The above simple example of js implementing StringBuffer is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.