当前位置: 代码迷 >> JavaScript >> JScript中没clone方法,自己写个玩clone玩玩
  详细解决方案

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

热度:265   发布时间:2012-11-19 10:18:51.0
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;
?}???

  相关解决方案