说明(2017.3.31):
1. 浅拷贝,只有值属性,没有引用属性。
2. 在原对象里面添加一个copy方法,返回本对象内的所有值属性。
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 </head> 7 <body> 8 <script type="text/javascript"> 9 var person = { 10 name: "张三", 11 age: "19", 12 gender: "男", 13 copy: function(){ 14 var temp = {}; 15 for(var k in this){ 16 temp[k] = this[k]; 17 } 18 return temp; 19 } 20 }; 21 var p = person.copy(); 22 p.name = "李四"; 23 p.age = "29"; 24 p.gender = "女"; 25 </script> 26 </body> 27 </html>