Skip to content

cloneDeepWith

js
_.cloneDeepWith(value, [customizer])

此方法与 _.cloneWith 类似,不同之处在于它以递归方式克隆 value

¥This method is like _.cloneWith except that it recursively clones value.

新增于

¥Since

4.0.0

参数

¥Arguments

  1. value (*):要递归克隆的值。

    ¥value ()*: The value to recursively clone.

  2. [customizer] (函数):自定义克隆的函数。

    ¥[customizer] (Function): The function to customize cloning.

返回

¥Returns

(*):返回深度克隆的值。

¥()*: Returns the deep cloned value.

示例

¥Example

js
function customizer(value) {
  if (_.isElement(value)) {
    return value.cloneNode(true);
  }
}

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

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

Lodash v4.17 中文网 - 粤ICP备13048890号