lib/object-tools.js
function clone (input) {
  var output
  if (typeof input === 'object' && !Array.isArray(input) && input !== null) {
    output = {}
    for (var prop in input) {
      output[prop] = input[prop]
    }
    return output
  } else if (Array.isArray(input)) {
    output = []
    input.forEach(function (item) {
      output.push(clone(item))
    })
    return output
  } else {
    return input
  }
}
function clone (input) {
  var output
  if (typeof input === 'object' && !Array.isArray(input) && input !== null) {
    output = {}
    for (var prop in input) {
      output[prop] = input[prop]
    }
    return output
  } else if (Array.isArray(input)) {
    output = []
    input.forEach(function (item) {
      output.push(clone(item))
    })
    return output
  } else {
    return input
  }
}
function clone ( input ) { var output if ( typeof input === 'object' && ! Array . isArray ( input ) && input !== null ) { output = { } for ( var prop in input ) { output [ prop ] = input [ prop ] } return output } else if ( Array . isArray ( input ) ) { output = [ ] input . forEach ( function ( item ) { output . push ( clone ( item ) ) } ) return output } else { return input } }
Clones an object or array
@param {object|array} input - the input to clone
@returns {object|array}
@static
@example
> date = new Date()
Fri May 09 2014 13:54:34 GMT+0200 (CEST)
> o.clone(date)
{}  // a Date instance doesn't own any properties
> date.clive = 'hater'
'hater'
> o.clone(date)
{ clive: 'hater' }
> array = [1,2,3]
[ 1, 2, 3 ]
> newArray = o.clone(array)
[ 1, 2, 3 ]
> array === newArray
false
Clones an object or array