//返回新对象,双方互不影响
function clone(obj){   
    //alert('clone');
    if(typeof(obj) != 'object') return obj;
    if(obj == null) return obj; //因为typeof(null) == object所以要加上这步
    var newObj = {};
    for(var i in obj){
        newObj[i] = clone(obj[i]);
        //alert('obj['+i+'] '+obj[i]);
    }
    return newObj;
}


function clone2(obj){
    //alert('clone2');
    function F(){}
    F.prototype = obj;
    return new F();
}

 

相关文章:

  • 2021-11-10
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-10-23
  • 2022-02-08
猜你喜欢
  • 2022-01-29
  • 2021-10-08
  • 2021-04-20
  • 2021-08-09
  • 2021-05-30
相关资源
相似解决方案