.clone() - DarthJDG/Mangler.js GitHub Wiki

Creates a deep copy of the mangler object and all its items.

.clone()

Returns

Returns a reference to the newly cloned mangler object.


The .clone() method attempts to create a deep copy of all objects in the .items[ ] array and builds a new mangler object from the clones.

data = { name: 'John' };
m = Mangler(data);
c = m.clone();

c.items[0].name = 'Fred';

/*
	m.items = [{ name: 'John' }];
	c.items = [{ name: 'Fred' }];
	data = { name: 'John' };
*/

Cloning object instances

By default, Mangler.js can only clone simple arrays, object literals, mangler objects and Date objects. If it encounters an object instance of a type that it doesn't recognise, its reference will be passed to the clone as is, pointing to the original object.

To add cloning support for all native JavaScript objects and typed arrays, see the Mangler-natives module.

To teach Mangler.js how to clone other objects, you can register handler functions for other object types. See Mangler.registerType() for more details.

⚠️ **GitHub.com Fallback** ⚠️