Skip to content

Library: clone()

Eugene Lazutkin edited this page Jul 3, 2018 · 1 revision

clone() module is a function, which creates a functional replicate of an object. It handles correctly Date, RegExp, Array objects as well as Object-based and null-based objects and primitives. It supports sparse arrays and non-standard properties on array objects.

Usage

In a module-enabled environment (like Babel) it can be accessed like that:

import clone from '@researchnow/reno/src/utils/clone';

In global-based environments (like a browser) it is frequently mapped to Reno.utils.clone.

clone(object)

The function takes the following arguments:

  • object is a valid JavaScript value to be cloned.

It returns a newly cloned value.

Examples

const initial = {_id: 1, value: 'x', next: {_id: 2, value: 'y', next: null}};
const result = clone(initial);
assert(isEqual(initial, result));

Clone this wiki locally