---
title: "JScript中没有clone方法，自己写个玩clone玩玩"
author: "fxk2006"
date: "2010-09-20T15:49:46Z"
tags: []
categories: ["Web前端"]
slug: "jscript-clone-clone"
draft: false
lastmod: "2010-09-20T15:49:46Z"
id: 768273
url: "https://fxk2006.iteye.com/blog/768273"
---

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