function clone obj if obj null typeof obj object return obj var temp n

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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;
}