| /** |
| * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/> |
| * Build: `lodash modularize underscore exports="node" -o ./underscore/` |
| * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> |
| * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE> |
| * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors |
| * Available under MIT license <http://lodash.com/license> |
| */ |
| var assign = require('./assign'), |
| baseCreateCallback = require('../internals/baseCreateCallback'), |
| isArray = require('./isArray'), |
| isObject = require('./isObject'), |
| slice = require('../internals/slice'); |
| |
| /** |
| * Creates a clone of `value`. If `isDeep` is `true` nested objects will also |
| * be cloned, otherwise they will be assigned by reference. If a callback |
| * is provided it will be executed to produce the cloned values. If the |
| * callback returns `undefined` cloning will be handled by the method instead. |
| * The callback is bound to `thisArg` and invoked with one argument; (value). |
| * |
| * @static |
| * @memberOf _ |
| * @category Objects |
| * @param {*} value The value to clone. |
| * @param {boolean} [isDeep=false] Specify a deep clone. |
| * @param {Function} [callback] The function to customize cloning values. |
| * @param {*} [thisArg] The `this` binding of `callback`. |
| * @returns {*} Returns the cloned value. |
| * @example |
| * |
| * var characters = [ |
| * { 'name': 'barney', 'age': 36 }, |
| * { 'name': 'fred', 'age': 40 } |
| * ]; |
| * |
| * var shallow = _.clone(characters); |
| * shallow[0] === characters[0]; |
| * // => true |
| * |
| * var deep = _.clone(characters, true); |
| * deep[0] === characters[0]; |
| * // => false |
| * |
| * _.mixin({ |
| * 'clone': _.partialRight(_.clone, function(value) { |
| * return _.isElement(value) ? value.cloneNode(false) : undefined; |
| * }) |
| * }); |
| * |
| * var clone = _.clone(document.body); |
| * clone.childNodes.length; |
| * // => 0 |
| */ |
| function clone(value) { |
| return isObject(value) |
| ? (isArray(value) ? slice(value) : assign({}, value)) |
| : value; |
| } |
| |
| module.exports = clone; |