SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 904 JavaScript
2016-01-28 01:16:24 -08:00
define(['./_baseClone'], function(baseClone) {
2015-12-16 17:53:20 -08:00
2016-10-30 20:06:57 -07:00
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
2016-11-13 22:49:46 -08:00
/** Used to compose bitmasks for cloning. */
var CLONE_SYMBOLS_FLAG = 4;
2015-12-16 17:53:20 -08:00
/**
* This method is like `_.clone` except that it accepts `customizer` which
2016-04-07 21:35:23 -07:00
* is invoked to produce the cloned value. If `customizer` returns `undefined`,
2015-12-16 17:53:20 -08:00
* cloning is handled by the method instead. The `customizer` is invoked with
2016-01-24 18:06:10 -08:00
* up to four arguments; (value [, index|key, object, stack]).
2015-12-16 17:53:20 -08:00
*
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 4.0.0
2015-12-16 17:53:20 -08:00
* @category Lang
* @param {*} value The value to clone.
* @param {Function} [customizer] The function to customize cloning.
* @returns {*} Returns the cloned value.
2016-04-19 22:17:16 -07:00
* @see _.cloneDeepWith
2015-12-16 17:53:20 -08:00
* @example
*
* function customizer(value) {
* if (_.isElement(value)) {
* return value.cloneNode(false);
* }
* }
*
2016-01-24 18:06:10 -08:00
* var el = _.cloneWith(document.body, customizer);
2015-12-16 17:53:20 -08:00
*
* console.log(el === document.body);
* // => false
* console.log(el.nodeName);
* // => 'BODY'
* console.log(el.childNodes.length);
* // => 0
*/
function cloneWith(value, customizer) {
2016-10-30 20:06:57 -07:00
customizer = typeof customizer == 'function' ? customizer : undefined;
2016-11-13 22:49:46 -08:00
return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
2015-12-16 17:53:20 -08:00
}
return cloneWith;
});