标签:html rip ini oct init func 黄色 name port
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
// 对象的拷贝
var obj1 = {
name: ‘zs‘,
age: 18,
sex: ‘男‘,
dog: {
name: ‘金毛‘,
age: 2,
yellow: ‘黄色‘
}
}
var obj2 = {};
// 封装函数 - 把o1 的成员,复制给o2
// 浅拷贝
function copy(o1, o2) {
for (var key in o1) {
o2[key] = o1[key];
}
}
copy(obj1, obj2);
// 修改obj1中的成员
obj1.name = ‘xxxx‘;
obj1.dog.name = ‘大黄‘;
console.dir(obj2);
</script>
</body>
</html>
标签:html rip ini oct init func 黄色 name port
原文地址:https://www.cnblogs.com/pxxdbk/p/12661746.html