cloneObj() : Deep Cloning - OrvilleChomer/orvObjLib GitHub Wiki

This method does a deep cloning of JavaScript object or array.

Note that any properties or array elements that contain a DOM item will not be copied.

Also note that if you try to clone an actual DOM element, it will fail!

Code Example #1

/*******************************************************************
    Make a deep cloned copy of [existingObj]
    This new objects will duplicate the same circular reference
    patterns that the original had!

    Any methods that the original had will NOT be copied into the new
    object!
 ******************************************************************/
var orvObjLib = new OrvObjLib(); // instantiate library object
var newObj = orvObjLib.cloneObj(existingObj);

Code Example #2

/*******************************************************************
    Make a deep cloned copy of [existingObj]
    This new objects will duplicate the same circular reference
    patterns that the original had!

    Any methods that the original had WILL be copied into the new
    object!
 ******************************************************************/
var orvObjLib = new OrvObjLib(); // instantiate library object
var newObj;

orvObjLib.setCopyMethods(true);
newObj = orvObjLib.cloneObj(existingObj);

Back to API List