This method is like `clone` except that it accepts `customizer` which is invoked to produce the cloned value. If `customizer` returns `undefined`, cloning is handled by the method instead. The `customizer` is invoked with up to four arguments (value [, index|key, object, stack]).
function customizer(value) {
if (isElement(value)) {
return value.cloneNode(false)
}
}
const el = cloneWith(document.body, customizer)
console.log(el === document.body)
// => false
console.log(el.nodeName)
// => 'BODY'
console.log(el.childNodes.length)
// => 0
| Name | Type | Attribute | Description |
|---|---|---|---|
| value | The value to clone. | ||
| customizer | The function to customize cloning. |
*
{
"comment": "/**\r\n * This method is like `clone` except that it accepts `customizer` which\r\n * is invoked to produce the cloned value. If `customizer` returns `undefined`,\r\n * cloning is handled by the method instead. The `customizer` is invoked with\r\n * up to four arguments (value [, index|key, object, stack]).\r\n *\r\n * @since 4.0.0\r\n * @category Lang\r\n * @param {*} value The value to clone.\r\n * @param {Function} [customizer] The function to customize cloning.\r\n * @returns {*} Returns the cloned value.\r\n * @see cloneDeepWith\r\n * @example\r\n *\r\n * function customizer(value) {\r\n * if (isElement(value)) {\r\n * return value.cloneNode(false)\r\n * }\r\n * }\r\n *\r\n * const el = cloneWith(document.body, customizer)\r\n *\r\n * console.log(el === document.body)\r\n * // => false\r\n * console.log(el.nodeName)\r\n * // => 'BODY'\r\n * console.log(el.childNodes.length)\r\n * // => 0\r\n */",
"meta": {
"range": [
996,
1170
],
"filename": "cloneWith.js",
"lineno": 35,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100000661",
"name": "cloneWith",
"type": "FunctionDeclaration",
"paramnames": [
"value",
"customizer"
]
},
"vars": {
"customizer": "cloneWith~customizer"
}
},
"description": "This method is like `clone` except that it accepts `customizer` which\ris invoked to produce the cloned value. If `customizer` returns `undefined`,\rcloning is handled by the method instead. The `customizer` is invoked with\rup to four arguments (value [, index|key, object, stack]).",
"since": "4.0.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Lang",
"value": "Lang"
}
],
"params": [
{
"type": {
"names": [
"*"
]
},
"description": "The value to clone.",
"name": "value"
},
{
"type": {
"names": [
"function"
]
},
"optional": true,
"description": "The function to customize cloning.",
"name": "customizer"
}
],
"returns": [
{
"type": {
"names": [
"*"
]
},
"description": "Returns the cloned value."
}
],
"see": [
"cloneDeepWith"
],
"examples": [
"function customizer(value) {\r if (isElement(value)) {\r return value.cloneNode(false)\r }\r}\r\rconst el = cloneWith(document.body, customizer)\r\rconsole.log(el === document.body)\r// => false\rconsole.log(el.nodeName)\r// => 'BODY'\rconsole.log(el.childNodes.length)\r// => 0"
],
"name": "cloneWith",
"longname": "cloneWith",
"kind": "function",
"scope": "global",
"___id": "T000002R000072",
"___s": true,
"filepath": "cloneWith.js"
}