concluir:
function stringbuffer () {this .__ strings__ = []; }; Stringbuffer.prototype.append = function (str) {this .__ Strings __. Push (str); devolver isso; }; // format string stringbuffer.prototype.appendFormat = function (str) {for (var i = 1; i <argumentos.length; i ++) {var parent = "// {" + (i - 1) + "//}"; var reg = novo regexp (pai, "g") str = str.Replace (reg, argumentos [i]); } this .__ strings __. push (str); devolver isso; } Stringbuffer.prototype.toString = function () {return this .__ strings __. Junção (''); }; Stringbuffer.prototype.clear = function () {this .__ strings__ = []; } Stringbuffer.prototype.size = function () {return this .__ strings __. Comprimento; }Chamadas instanciadas
var sbhtml = new StringBuffer (); sbhtml.append ('hello'); sbhtml.append ('mundo'); console.log (sbhtml.toString ());O exemplo simples acima do JS implementando StringBuffer é todo o conteúdo que eu compartilho com você. Espero que você possa lhe dar uma referência e espero que você possa apoiar mais o wulin.com.