第四种:拷贝继承
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//第四种:拷贝继承
//原理:将对象的成员复制一份给需要继承的对象
var cat = {
name : '小花',
age: 6,
sex:'女',
sayHi:function(){
console.log('Hello World!');
},
}
//创建需要继承的子对象
var catCopy = {};
for(var i in cat){
catCopy[i] = cat[i];
}
console.log(cat);
console.log(catCopy);
</script>
</body>
</html>