//節點克隆
function clon(obj){
var o;
switch (typeof obj){
case "undefined":
break;
case "string":
o = obj + '';
break;
case "number":
o = obj - 0;
break;
case "boolean":
o = obj;
break;
case "object":
if(obj === null){
o = null
}else{
if(obj instanceof Array){ //判斷是否是數組
for(var i = 0;i < obj.length;i++){
o.push(clon(obj[i]));
}
}else{
for(var k in obj){
o[k] = clon(obj[k]);
}
}
}
break;
default:
o = obj;
break;
}
return o;
}數組