运用Prototype可以为对象添加新的方法和属性

function StringBuilder() {
    this._string_ = new Array();
}
StringBuilder.prototype.Append = function(item) {
this._string_.push(item)
}
StringBuilder.prototype.toString = function() {
    return this._string_.join("");
}
//Test
var buffer = new StringBuilder();
buffer.Append("googlsfsfe");
buffer.Append("baiddu");
alert(buffer.toString());

posted on 2009-03-22 10:06  rosanshao  阅读(122)  评论(0)    收藏  举报