* The base implementation of `_.clone` without argument juggling or support * for `thisArg` binding. * * @private * @param {*} value The value to clone. * @param {boolean} [isDeep=false] Specify a deep clone. * @param {Function} [callback] The function to customize clon
(value, isDeep, callback, stackA, stackB)
| 35879 | * @returns {*} Returns the cloned value. |
| 35880 | */ |
| 35881 | function baseClone(value, isDeep, callback, stackA, stackB) { |
| 35882 | if (callback) { |
| 35883 | var result = callback(value); |
| 35884 | if (typeof result != 'undefined') { |
| 35885 | return result; |
| 35886 | } |
| 35887 | } |
| 35888 | // inspect [[Class]] |
| 35889 | var isObj = isObject(value); |
| 35890 | if (isObj) { |
| 35891 | var className = toString.call(value); |
| 35892 | if (!cloneableClasses[className]) { |
| 35893 | return value; |
| 35894 | } |
| 35895 | var ctor = ctorByClass[className]; |
| 35896 | switch (className) { |
| 35897 | case boolClass: |
| 35898 | case dateClass: |
| 35899 | return new ctor(+value); |
| 35900 | |
| 35901 | case numberClass: |
| 35902 | case stringClass: |
| 35903 | return new ctor(value); |
| 35904 | |
| 35905 | case regexpClass: |
| 35906 | result = ctor(value.source, reFlags.exec(value)); |
| 35907 | result.lastIndex = value.lastIndex; |
| 35908 | return result; |
| 35909 | } |
| 35910 | } else { |
| 35911 | return value; |
| 35912 | } |
| 35913 | var isArr = isArray(value); |
| 35914 | if (isDeep) { |
| 35915 | // check for circular references and return corresponding clone |
| 35916 | var initedStack = !stackA; |
| 35917 | stackA || (stackA = getArray()); |
| 35918 | stackB || (stackB = getArray()); |
| 35919 | |
| 35920 | var length = stackA.length; |
| 35921 | while (length--) { |
| 35922 | if (stackA[length] == value) { |
| 35923 | return stackB[length]; |
| 35924 | } |
| 35925 | } |
| 35926 | result = isArr ? ctor(value.length) : {}; |
| 35927 | } |
| 35928 | else { |
| 35929 | result = isArr ? slice(value) : assign({}, value); |
| 35930 | } |
| 35931 | // add array properties assigned by `RegExp#exec` |
| 35932 | if (isArr) { |
| 35933 | if (hasOwnProperty.call(value, 'index')) { |
| 35934 | result.index = value.index; |
| 35935 | } |
| 35936 | if (hasOwnProperty.call(value, 'input')) { |
| 35937 | result.input = value.input; |
| 35938 | } |