Archive: June 07, 2007
-
Because I'm sure it'll come in handy later, here's a javascript object clone function:
function clone(obj){
if(obj == null || typeof(obj) != 'object')
return obj;
var temp = {};
for(var key in obj)
temp[key] = clone(obj[key]);
return temp;
}
Update: From feedback in the comments, a better version is:
function clone(obj){
if(obj == null || typeof(obj) != 'object')
return obj;
var temp = new obj.constructor(); // changed (twice)
for(var key in obj)
temp[key] = clone(obj[key]);
return temp;
}
¶
Tags: [Code, Javascript]
|
Generated in about 0.048s. (Used 7 db queries) |
new⇒Girls, please don't get breast implants
you people implants are fine thesedays but they are like body organsnot e...
kym: Oct 15, 5:25pm