常用js函式(不斷更新)
阿新 • • 發佈:2019-01-28
/** * 物件克隆 **/ cloneObj : function(obj){ var This = this; obj.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.cloneObj(this[key]); }else{ objClone[key] = this[key]; } } } objClone.toString = this.toString; objClone.valueOf = this.valueOf; return objClone; } return obj.Clone(); }