Home >Web Front-end >JS Tutorial >The speed battle between String and StringBuffer in JavaScript_javascript tips

The speed battle between String and StringBuffer in JavaScript_javascript tips

WBOY
WBOYOriginal
2016-05-16 18:30:50917browse

There is no StringBuffer class in Javascript when displaying the situation. A mainstream implementation of the Javascript StringBuffer class is to construct a StringBuffer class through prototype.
StringBuffer.js

Copy code The code is as follows:

function StringBuffer(){
this.content = new Array;
}
StringBuffer.prototype.append = function( str ){
this.content.push( str );
}
StringBuffer.prototype.toString = function(){
return this.content.join("");
}

Now let us write a test case:
TestStringBUffer.html
Copy code The code is as follows:


test