MCPcopy
hub / github.com/lodash/lodash / initCloneByTag

Function initCloneByTag

lodash.js:6280–6314  ·  view source on GitHub ↗

* Initializes an object clone based on its `toStringTag`. * * **Note:** This function only supports cloning values with tags of * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. * * @private * @param {Object} object The object to clone. *

(object, tag, isDeep)

Source from the content-addressed store, hash-verified

6278 * @returns {Object} Returns the initialized clone.
6279 */
6280 function initCloneByTag(object, tag, isDeep) {
6281 var Ctor = object.constructor;
6282 switch (tag) {
6283 case arrayBufferTag:
6284 return cloneArrayBuffer(object);
6285
6286 case boolTag:
6287 case dateTag:
6288 return new Ctor(+object);
6289
6290 case dataViewTag:
6291 return cloneDataView(object, isDeep);
6292
6293 case float32Tag: case float64Tag:
6294 case int8Tag: case int16Tag: case int32Tag:
6295 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
6296 return cloneTypedArray(object, isDeep);
6297
6298 case mapTag:
6299 return new Ctor;
6300
6301 case numberTag:
6302 case stringTag:
6303 return new Ctor(object);
6304
6305 case regexpTag:
6306 return cloneRegExp(object);
6307
6308 case setTag:
6309 return new Ctor;
6310
6311 case symbolTag:
6312 return cloneSymbol(object);
6313 }
6314 }
6315
6316 /**
6317 * Inserts wrapper `details` in a comment at the top of the `source` body.

Callers 1

baseCloneFunction · 0.85

Calls 5

cloneArrayBufferFunction · 0.85
cloneDataViewFunction · 0.85
cloneTypedArrayFunction · 0.85
cloneRegExpFunction · 0.85
cloneSymbolFunction · 0.85

Tested by

no test coverage detected