<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type="text/javascript"> window.onload = function () { var obj = { a : { b : 10} }; function copy(obj)//浅拷贝 { var newObj = {}; for(var attr in obj) { newObj[attr] = obj[attr] } return newObj; } function deepcopy(obj) { if(typeof obj != 'object') { return obj; } var newobj = {}; for(var attr in obj) { newobj[attr] = deepcopy(obj[attr]); } return newobj; } var obj2 = deepcopy(obj); obj2.a.b = 50; alert(obj.a.b); } </script> </head> <body> </body> </html>