代码如下:var Person={name:'default name', getName:function(){ return this.name} }
var reader=clone(Person);
reader.name='张三';
alert(reader.getName())

解决方案 »

  1.   

    clone应该是自定义的函数吧function clone(obj){
      var his=new Object();
      for(var p in obj)
      {
        his[p]=obj[p];
      } 
      return his;
    }
      

  2.   

    请问为什么要clone,这不是多此一举吗? 直接这样写不就完了吗var Person={name:'default name', getName:function(){ return this.name} }
    var reader=Person;
    reader.name='张三';
    alert(reader.getName())
      

  3.   

    哦 我明白了,要是这么写会破坏Person的结构,是我看书不仔细,后几节有个clone的定义function clone(object){
        function F(){};
    F.prototype=object;
    return new F;
    }