Function default

  • 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).

    Parameters

    • value: any

      The value to clone.

    • Optional customizer: ((...any) => any)

      The function to customize cloning.

      Optional
        • (...any): any
        • Parameters

          • Rest ...any: any[]
            Rest

          Returns any

    Returns any

    Returns the cloned value.

    Since

    5.3.0

    See

    cloneDeepWith

    Example

    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