Skip to content

Instantly share code, notes, and snippets.

@ziluo
Created April 9, 2013 07:43
Show Gist options
  • Save ziluo/5343757 to your computer and use it in GitHub Desktop.
Save ziluo/5343757 to your computer and use it in GitHub Desktop.
对象的深度复制
Object.prototype.Clone = function(){
var objClone;
if (this.constructor == Object){
objClone = new this.constructor();
}else{
objClone = new this.constructor(this.valueOf());
}
for(var key in this){
if ( objClone[key] != this[key] ){
if ( typeof(this[key]) == ‘object’ ){
objClone[key] = this[key].Clone();
}else{
objClone[key] = this[key];
}
}
}
objClone.toString = this.toString;
objClone.valueOf = this.valueOf;
return objClone;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment