首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-11-19 
JScript中没有clone方法,自己写个玩clone玩玩Object.prototype.Clone function()?{??? var objClone???

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

热点排行
Bad Request.