Is there a quick way to “super” deep clone a node, including its properties? (and methods, I think)
I have something like this:
var theSource = document.getElementById("someDiv")
theSource.dictator = "stalin";
var theClone = theSource.cloneNode(true);
alert(theClone.dictator);
The new cloned object has no property dictator. Now, let's say I have a thousand properties related to theSource- how can I (implicitly) transfer / copy them to a clone?
// EDIT
@Fabrizio
Your answer is hasOwnPropertynot working properly, so I adjusted it. This is the solution I was looking for:
temp = obj.cloneNode(true);
for(p in obj) {
if(obj.hasOwnProperty(p)) { eval("temp."+p+"=obj."+p); }
}
source
share