返回列表

Raphle对象深度克隆

默认分类 2014/12/10 01:51

代码如下:

    function clone(obj) {
        if (typeof obj == "function" || Object(obj) !== obj) {
            return obj;
        }
        var res = new obj.constructor;
        for (var key in obj) if (obj['hasOwnProperty'](key)) {
            res[key] = clone(obj[key]);
        }
        return res;
    }