Function cloneWith

  • 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 one argument (value).

    Type Parameters

    • T

    Parameters

    • value: T

      The value to clone.

    • Optionalcustomizer: ((value: T, key?: PropertyName, object?: any) => any)

      The function to customize cloning.

        • (value, key?, object?): any
        • Parameters

          • value: T
          • Optionalkey: PropertyName
          • Optionalobject: any

          Returns any

    Returns any

    Returns the cloned value.

    4.0.0

    cloneDeepWith

    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