View Full Version : Ext.clone should check for a custom clone(), _clone() or another suitable method

18 Nov 2011, 6:57 AM
I have faced infinite recursion errors multiple times with Ext.clone trying to clone an object which contained circular references.

To avoid such situations, I think that it should check for clone, _clone or another suitably named method on an object and if available, use the return value of that object as the clone instead of setting out to recursively clone the object itself.

I currently use a work-around where Ext.clone checks for obj.nodeType and obj.cloneNode on an object (for dom nodes) and is both exist, uses obj.cloneNode instead for cloning. So I add a dummy value to nodeType for my objects containing circular references and then add a method cloneNode which returns the object itself to overcome current behavior of infinite recursion by Ext.clone.

18 Nov 2011, 2:58 PM
Test case I can use to create an official fix with?

19 Nov 2011, 12:58 AM
Here's it:

var a={};
var b={};
var c=Ext.clone(a);

And the error:
RangeError: Maximum call stack size exceeded