As shown below:
<strong>There is a StringBuffer class in JAVA, but there is no following to implement a simple StringBuffer class for js. </strong> //Create a StringBuffer class. There are two methods for this class: one is the append method and the other is the 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('<li>');//Add a string, the same as buffer.append('<div><a href="#"><img src="');buffer.append(companymsg.userPhoto);buffer.append('"></img></a></div>');buffer.append('<div>');buffer.append('<div><a>');buffer.append('<div><a>'+ companiesg.companyMasterName+ '</a> <span>'+ FormatDate(companymsg.crtime) + '</span></div>');buffer.append('</div><div>');if (companymsg.newsId != null) {buffer.append('<a href="'+companymsg.newsId+'">'+ companiesg.newsTitle + '</a>');} else {buffer.append('<a href="javascript:void(0)">'+ companiesg.newsTitle + '</a>');} if (companymsg.newsContent != null) {buffer.append('<div><span>>>Expan</span></div>');buffer.append('<div>'+ companiesg.newsContent + '</div>');}buffer.append('</div>');buffer.append('</div>');buffer.append('<div><a href="javascript:void(0)" style="float:left"><span></span></a><input type="text"></input></div>');buffer.append('</div></li>');return buffer.toString();//Split into a string}The above article briefly discusses the implementation method and use of StringBuffer class in js. This is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.