Javascript 深度克隆

Object.prototype.clone=function(){
  var o=this.constructor===Array?[]:{};
  for(var e in this){
  o[e]=typeof this[e]==="object"?this[e].clone():this[e];
  }
  return o;
}

举例:
var obj1 = {name: "flondon", add: "China"};
console.info(obj1.clone());

posted @ 2012-09-24 22:48  wcp_spring  阅读(161)  评论(0)    收藏  举报