<html> <script> function StringBuffer(){ this.string = new Array; //创建Array对象存储字符串 } StringBuffer.prototype.append = function(str){ //把参数str附加到字符串数组 this.string .push(str); } StringBuffer.prototype.toString = function(){ //用join方法返回真正的字符串 this.string.join(""); } var oBuffer = new StringBuffer(); d1 = new Date(); for (var i=0; i < 10000; i++) { oBuffer.append("text"); } var sResult = oBuffer.toString(); d2 = new Date(); document.write(d2.getTime()-d1.getTime()); </script> <body> </body> </html>
javaScript 之实现StringBuffer
最新推荐文章于 2018-02-24 09:52:17 发布