Friends

深度克隆

deepClone = function(obj) { //deep clone a plain object
    var input = __slice.call(arguments, 1),
        key,
        value;
    for (var i = 0, length = input.length; i < length; i++) {
        for (key in input[i]) {
            value = input[i][key];
            if (input[i].hasOwnProperty(key) && value !== undefined) {
                // Clone objects
                if (__isPlainObject(value)) {
                    obj[key] = __isPlainObject(obj[key]) ?
                        __extend({}, obj[key], value) :
                        // Don't extend strings, arrays, etc. with objects
                        __extend({}, value);
                    // Copy everything else by reference
                } else {
                    obj[key] = value;
                }
            }
        }
    }
    return obj;
}
Written on August 27, 2015