packages/utils/deepClone.js
/**
 * This is just a simple version of deep copy
 * Has a lot of edge cases bug
 * If you want to use a perfect deep copy, use lodash's _.cloneDeep
 */
This is just a simple version of deep copy
Has a lot of edge cases bug
If you want to use a perfect deep copy, use lodash's _.cloneDeep
This is just a simple version of deep copy Has a lot of edge cases bug If you want to use a perfect deep copy use lodash ' s _ . cloneDeep
function deepClone(item) {
  if (!item) {
    return item
  } 
  var types = [Number, String, Boolean],
    result
  types.forEach(function (type) {
    if (item instanceof type) {
      result = type(item)
    }
  })
  if (typeof result == 'undefined') {
    if (Object.prototype.toString.call(item) === '[object Array]') {
      result = []
      item.forEach(function (child, index, array) {
        result[index] = deepClone(child)
      })
    } else if (typeof item == 'object') {
      if (item.nodeType && typeof item.cloneNode == 'function') {
        result = item.cloneNode(true)
      } else if (!item.prototype) {
        if (item instanceof Date) {
          result = new Date(item)
        } else {
          result = {}
          for (var i in item) {
            result[i] = deepClone(item[i])
          }
        }
      } else {
        if (false && item.constructor) {
          result = new item.constructor()
        } else {
          result = item
        }
      }
    } else {
      result = item
    }
  }
  return result
}
function deepClone ( item ) { if ( ! item ) { return item } var types = [ Number , String , Boolean ] , result types . forEach ( function ( type ) { if ( item instanceof type ) { result = type ( item ) } } ) if ( typeof result == 'undefined' ) { if ( Object . prototype . toString . call ( item ) === '[object Array]' ) { result = [ ] item . forEach ( function ( child , index , array ) { result [ index ] = deepClone ( child ) } ) } else if ( typeof item == 'object' ) { if ( item . nodeType && typeof item . cloneNode == 'function' ) { result = item . cloneNode ( true ) } else if ( ! item . prototype ) { if ( item instanceof Date ) { result = new Date ( item ) } else { result = { } for ( var i in item ) { result [ i ] = deepClone ( item [ i ] ) } } } else { if ( false && item . constructor ) { result = new item . constructor ( ) } else { result = item } } } else { result = item } } return result }
This is just a simple version of deep copy
 Has a lot of edge cases bug
 If you want to use a perfect deep copy, use lodash's _.cloneDeep
This is just a simple version of deep copy Has a lot of edge cases bug If you want to use a perfect deep copy use lodash ' s _ . cloneDeep
// null, undefined values check // normalizing primitives if someone did new String('aaa'), or new Number('444'); // testing that this is DOM // check that this is a literal // it is an object literal // depending what you would like here, // just keep the reference, or create new object // would not advice to do that, reason? Read below