当前位置:Gxlcms > JavaScript > 复制js对象方法(详解)

复制js对象方法(详解)

时间:2021-07-01 10:21:17 帮助过:22人阅读

代码如下:
CSSCommonJS.DeepCopy = function (json) {
    if (typeof json == 'number' || typeof json == 'string' || typeof json == 'boolean') {
        return json;
    } else if (typeof json == 'object') {
        if (json instanceof Array) {
            var newArr = [], i, len = json.length;
            for (i = 0; i < len; i++) {
                newArr[i] = arguments.callee(json[i]);
            }
            return newArr;
        } else {
            var newObj = {};
            for (var name in json) {
                newObj[name] = arguments.callee(json[name]);
            }
            return newObj;
        }
    }
}

人气教程排行