MCPcopy
hub / github.com/lodash/lodash / baseClone

Function baseClone

lodash.js:2667–2741  ·  view source on GitHub ↗

* The base implementation of `_.clone` and `_.cloneDeep` which tracks * traversed objects. * * @private * @param {*} value The value to clone. * @param {boolean} bitmask The bitmask flags. * 1 - Deep clone * 2 - Flatten inherited properties * 4 - Clone symb

(value, bitmask, customizer, key, object, stack)

Source from the content-addressed store, hash-verified

2665 * @returns {*} Returns the cloned value.
2666 */
2667 function baseClone(value, bitmask, customizer, key, object, stack) {
2668 var result,
2669 isDeep = bitmask & CLONE_DEEP_FLAG,
2670 isFlat = bitmask & CLONE_FLAT_FLAG,
2671 isFull = bitmask & CLONE_SYMBOLS_FLAG;
2672
2673 if (customizer) {
2674 result = object ? customizer(value, key, object, stack) : customizer(value);
2675 }
2676 if (result !== undefined) {
2677 return result;
2678 }
2679 if (!isObject(value)) {
2680 return value;
2681 }
2682 var isArr = isArray(value);
2683 if (isArr) {
2684 result = initCloneArray(value);
2685 if (!isDeep) {
2686 return copyArray(value, result);
2687 }
2688 } else {
2689 var tag = getTag(value),
2690 isFunc = tag == funcTag || tag == genTag;
2691
2692 if (isBuffer(value)) {
2693 return cloneBuffer(value, isDeep);
2694 }
2695 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2696 result = (isFlat || isFunc) ? {} : initCloneObject(value);
2697 if (!isDeep) {
2698 return isFlat
2699 ? copySymbolsIn(value, baseAssignIn(result, value))
2700 : copySymbols(value, baseAssign(result, value));
2701 }
2702 } else {
2703 if (!cloneableTags[tag]) {
2704 return object ? value : {};
2705 }
2706 result = initCloneByTag(value, tag, isDeep);
2707 }
2708 }
2709 // Check for circular references and return its corresponding clone.
2710 stack || (stack = new Stack);
2711 var stacked = stack.get(value);
2712 if (stacked) {
2713 return stacked;
2714 }
2715 stack.set(value, result);
2716
2717 if (isSet(value)) {
2718 value.forEach(function(subValue) {
2719 result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
2720 });
2721 } else if (isMap(value)) {
2722 value.forEach(function(subValue, key) {
2723 result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
2724 });

Callers 9

cloneFunction · 0.85
cloneWithFunction · 0.85
cloneDeepFunction · 0.85
cloneDeepWithFunction · 0.85
lodash.jsFile · 0.85
conformsFunction · 0.85
iterateeFunction · 0.85
matchesFunction · 0.85
matchesPropertyFunction · 0.85

Calls 13

customizerFunction · 0.85
isObjectFunction · 0.85
initCloneArrayFunction · 0.85
copyArrayFunction · 0.85
cloneBufferFunction · 0.85
initCloneObjectFunction · 0.85
copySymbolsInFunction · 0.85
baseAssignInFunction · 0.85
copySymbolsFunction · 0.85
baseAssignFunction · 0.85
initCloneByTagFunction · 0.85
arrayEachFunction · 0.85

Tested by

no test coverage detected