lib/altshift/core/base.js
function clone(obj, deep) {

    if (!obj || typeof obj !== "object" || isFunction(obj)) {
        // null, undefined, any non-object, or function
        return obj;   // anything
    }
    if (obj instanceof Date) {
        // Date
        return new Date(obj.getTime());   // Date
    }
    var result, index, length, value;
    if (isArray(obj)) {
        // array
        result = [];
        if (deep) {
            for (index = 0, length = obj.length; index < length; index += 1) {
                if (index in obj) {
                    value = obj[index];
                    value = value.clone ? value.clone(true) : clone(value);
                    result.push(clone(value));
                }
            }
        } else {
            for (index = 0, length = obj.length; index < length; index += 1) {
                if (index in obj) {
                    result.push(value);
                }
            }
        }
        return result;
    }

    //Default implementation
    if (obj.clone) {
        return obj.clone(obj, deep);
    }

    // generic objects
    result = obj.constructor ? new obj.constructor() : {};

    for (index in obj) {
        if (true) {//jslint validation
            value = obj[index];
            if (
                !(index in result) ||
                (result[index] !== value && (!(index in EMPTY) || EMPTY[index] !== value))
            ) {
                result[index] = clone(value);
            }
        }
    }

    return result; // Object
}
function clone(obj, deep) {

    if (!obj || typeof obj !== "object" || isFunction(obj)) {
        // null, undefined, any non-object, or function
        return obj;   // anything
    }
    if (obj instanceof Date) {
        // Date
        return new Date(obj.getTime());   // Date
    }
    var result, index, length, value;
    if (isArray(obj)) {
        // array
        result = [];
        if (deep) {
            for (index = 0, length = obj.length; index < length; index += 1) {
                if (index in obj) {
                    value = obj[index];
                    value = value.clone ? value.clone(true) : clone(value);
                    result.push(clone(value));
                }
            }
        } else {
            for (index = 0, length = obj.length; index < length; index += 1) {
                if (index in obj) {
                    result.push(value);
                }
            }
        }
        return result;
    }

    //Default implementation
    if (obj.clone) {
        return obj.clone(obj, deep);
    }

    // generic objects
    result = obj.constructor ? new obj.constructor() : {};

    for (index in obj) {
        if (true) {//jslint validation
            value = obj[index];
            if (
                !(index in result) ||
                (result[index] !== value && (!(index in EMPTY) || EMPTY[index] !== value))
            ) {
                result[index] = clone(value);
            }
        }
    }

    return result; // Object
}
function clone ( obj , deep ) { if ( ! obj || typeof obj !== "object" || isFunction ( obj ) ) { // null, undefined, any non-object, or function return obj ; // anything } if ( obj instanceof Date ) { // Date return new Date ( obj . getTime ( ) ) ; // Date } var result , index , length , value ; if ( isArray ( obj ) ) { // array result = [ ] ; if ( deep ) { for ( index = 0 , length = obj . length ; index < length ; index += 1 ) { if ( index in obj ) { value = obj [ index ] ; value = value . clone ? value . clone ( true ) : clone ( value ) ; result . push ( clone ( value ) ) ; } } } else { for ( index = 0 , length = obj . length ; index < length ; index += 1 ) { if ( index in obj ) { result . push ( value ) ; } } } return result ; } //Default implementation if ( obj . clone ) { return obj . clone ( obj , deep ) ; } // generic objects result = obj . constructor ? new obj . constructor ( ) : { } ; for ( index in obj ) { if ( true ) { //jslint validation value = obj [ index ] ; if ( ! ( index in result ) || ( result [ index ] !== value && ( ! ( index in EMPTY ) || EMPTY [ index ] !== value ) ) ) { result [ index ] = clone ( value ) ; } } } return result ; // Object }
Clone an object

@param {*} obj
@return {*}
Clone an object