标签:
function StringBuffer() { this.__strings__ = []; }; StringBuffer.prototype.Append = function (str) { this.__strings__.push(str); return this; }; //格式化字符串 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; }
var sbHtml=new StringBuffer(); sbHtml.Append(‘hello‘); sbHtml.Append(‘world‘); console.log(sbHtml.ToString());
标签:
原文地址:http://www.cnblogs.com/sword-successful/p/5726269.html