<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>深克隆</title>
<script>
function clone(obj)
{
if(typeof obj=='object')
{
if(obj instanceof Array)
{
var result=[];
for(var i=0;i<obj.length;i++)
{
result[i]=clone(obj[i]);
}
return result;
}
else
{
var result={};
for(var i in obj)
{
result[i]=clone(obj[i]);
}
return result;
}
}
else
{
return obj;
}
}
var obj1=[12, {a: 11, b: 22}, 5];
var obj2=clone(obj1);
obj2[1].a+=5;
console.log(obj1, obj2);
</script>
</head>
<body>
</body>
</html>