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
Release: 2016-05-16 18:30:50
Original
914 people have browsed it

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template