accomplir:
function stringBuffer () {this .__ Strings__ = []; }; StringBuffer.prototype.append = function (str) {this .__ chaînes __. Push (str); retourner ceci; }; // Format String StringBuffer.prototype.ApendFormat = fonction (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 .__ cordes __. push (str); retourner ceci; } Stringbuffer.prototype.toString = function () {return this .__ Strings __. JOIN (''); }; StringBuffer.prototype.Clear = function () {this .__ Strings__ = []; } Stringbuffer.prototype.size = function () {return this .__ chaînes __. }Appels instanciés
var sbhtml = new StringBuffer (); sbhtml.append ('bonjour'); SBHTML.APPEND ('World'); console.log (sbhtml.toString ());L'exemple simple ci-dessus de JS implémentation de StringBuffer est tout le contenu que je partage avec vous. J'espère que vous pourrez vous faire référence et j'espère que vous pourrez soutenir Wulin.com plus.