Implementation and use of the StringBuffer class in js
JAVA has a StringBuffer class, but js does not implement a simple StringBuffer class.
// Create a StringBuffer class. this class has two methods: append method and toString method function StringBuffer () {this. _ strings _ = [];}; StringBuffer. prototype. append = function (str) {this. _ strings __. push (str) ;}; StringBuffer. prototype. toString = function () {return this. _ strings __. join ('');};
Use of StringBuffer:
// This instance is mainly used to splice strings
Function GnComCard (companymsg) {var buffer = new StringBuffer (); // declare an Object buffer. append (''); // Append the string, which is the same as buffer. append (''); buffer. append (''); buffer. append (''+ companymsg. companyMasterName + ''+ FormatDate (companymsg. crtime) + ''); buffer. append (''); if (companymsg. newsId! = Null) {buffer. append (''+ companymsg. newsTitle + '');} else {buffer. append (''+ companymsg. newsTitle + '');} if (companymsg. newsContent! = Null) {buffer. append ('> Expand'); buffer. append (''+ companymsg. newsContent + '');} buffer. append (''); buffer. append (''); Buffer. append (''); Return buffer. toString (); // concatenate a string}