本文实例讲述了JavaScript实现Java中StringBuffer的方法。分享给大家供大家参考。具体如下:
Javascript StringBuffer类的实现是通过prototype构造一个StringBuffer类,代码如下:
function StringBuffer() { this.__strings__ = new Array(); } StringBuffer.prototype.append = function(str) { this.__strings__.push(str); }; StringBuffer.prototype.toString = function() { return this.__strings__.join(""); };
例子:
希望本文所述对大家的javascript程序设计有所帮助。