1 |
3a515b92
|
cagy
|
var baseClone = require('./_baseClone');
|
2 |
|
|
|
3 |
|
|
/** Used to compose bitmasks for cloning. */
|
4 |
|
|
var CLONE_SYMBOLS_FLAG = 4;
|
5 |
|
|
|
6 |
|
|
/**
|
7 |
|
|
* This method is like `_.clone` except that it accepts `customizer` which
|
8 |
|
|
* is invoked to produce the cloned value. If `customizer` returns `undefined`,
|
9 |
|
|
* cloning is handled by the method instead. The `customizer` is invoked with
|
10 |
|
|
* up to four arguments; (value [, index|key, object, stack]).
|
11 |
|
|
*
|
12 |
|
|
* @static
|
13 |
|
|
* @memberOf _
|
14 |
|
|
* @since 4.0.0
|
15 |
|
|
* @category Lang
|
16 |
|
|
* @param {*} value The value to clone.
|
17 |
|
|
* @param {Function} [customizer] The function to customize cloning.
|
18 |
|
|
* @returns {*} Returns the cloned value.
|
19 |
|
|
* @see _.cloneDeepWith
|
20 |
|
|
* @example
|
21 |
|
|
*
|
22 |
|
|
* function customizer(value) {
|
23 |
|
|
* if (_.isElement(value)) {
|
24 |
|
|
* return value.cloneNode(false);
|
25 |
|
|
* }
|
26 |
|
|
* }
|
27 |
|
|
*
|
28 |
|
|
* var el = _.cloneWith(document.body, customizer);
|
29 |
|
|
*
|
30 |
|
|
* console.log(el === document.body);
|
31 |
|
|
* // => false
|
32 |
|
|
* console.log(el.nodeName);
|
33 |
|
|
* // => 'BODY'
|
34 |
|
|
* console.log(el.childNodes.length);
|
35 |
|
|
* // => 0
|
36 |
|
|
*/
|
37 |
|
|
function cloneWith(value, customizer) {
|
38 |
|
|
customizer = typeof customizer == 'function' ? customizer : undefined;
|
39 |
|
|
return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
module.exports = cloneWith;
|