Home  >  Article  >  Web Front-end  >  复制js对象方法(详解)_javascript技巧

复制js对象方法(详解)_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:29:451057browse
复制代码 代码如下:

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                 newArr[i] = arguments.callee(json[i]);
            }
            return newArr;
        } else {
            var newObj = {};
            for (var name in json) {
                newObj[name] = arguments.callee(json[name]);
            }
            return newObj;
        }
    }
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn