> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/lang/clonewith.md).

# \_.cloneWith（数据的浅克隆）

**语法：**

```javascript
_.cloneWith(value, [customizer])
```

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L11063)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.clonewith)

**描述：**

这个方法类似[`_.clone`](https://github.com/xiaoxiami/lodash/tree/ecee857b272d1a95fe35e154e2d64974a3f29261/_.clone)，除了它接受一个`customizer`定制返回的克隆值。 如果`customizer`返回`undefined`将会使用拷贝方法代替处理。 customizer 调用4个参数：*(value \[, index|key, object, stack])*。

**开始版本：**&#x34;.0.0

**参数：**

* `value (*)`: 要克隆的值。
* `[customizer] (Function)`: 用来自定义克隆的函数。

**返回值：**

* `(*)`: 返回克隆值。

**例子：**

```javascript
function customizer(value) {
  if (_.isElement(value)) {
    return value.cloneNode(false);
  }
}

var el = _.cloneWith(document.body, customizer);

console.log(el === document.body);
// => false
console.log(el.nodeName);
// => 'BODY'
console.log(el.childNodes.length);
// => 0
```
