完全没有问题.
你自己代码写错了。或者是两次弹出jinru,而你自己以为没有执行.
<script>function StringBuffer(){ 
    this._strings=new Array; 
    }; 
StringBuffer.prototype.append= function (str){ 
    //this._strings.push(str); 
    alert(str); 
    }; 
StringBuffer.prototype.toString= function(){ 
    return this._strings.join(" "); 
    }; 
     
function buffer(){ 
var oBuffer=new StringBuffer(); 
oBuffer.append('sadf');//--------------------------1 
alert('jinru'); 

buffer()
</script>

解决方案 »

  1.   


    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function StringBuffer(){ 
      this._strings=new Array; 
    }; StringBuffer.prototype.append= function (str){ 
      this._strings.push(str);
    }; StringBuffer.prototype.toString= function(){ 
        return this._strings.join(" "); 
    }; 
         
    function buffer(){ 
    var oBuffer=new StringBuffer(); 
    oBuffer.append('aaa');
    oBuffer.append('ggg');
    alert(oBuffer.toString()); 

    buffer();
    //-->
    </SCRIPT>
      

  2.   

    你的 oBuffer.append('sadf');--------------------------1 
    就是 相当于 在 调用属性 StringBuffer.prototype.append= function (str){
        //this._strings.push(str);
        alert('jinru');
        }; 就等于     alert('jinru');你换个值试试?
      

  3.   

    你要 可以 改属性 
    为 StringBuffer.prototype.append= function (str){
        //this._strings.push(str);
        alert(str);//这里是 你要传递的参数
        };  
    这样 你一次 弹出 'sadf' 
    第二次'jinru'