日期:2014-05-16  浏览次数:20376 次

JScript中没有clone方法,自己写个玩clone玩玩

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;
?}???