本文實例講述了Javascript對象Clone用法。分享給大家供大家參考。具體如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Object.prototype.Clone=function() { var objClone=new this.constructor(); //這裡是創建一個與被Clone對象相同結構的對象 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]; } } } if(!objClone || (''+objClone)=='') { return (new String(this)+objClone)?this:objClone; } else { objClone.toString=this.toString; return objClone; } }