<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>原型对象的继承</title>
</head>
<body>
<script>
function Father() {
this.name = '马云'
}
Father.prototype.init = function () {
console.log('Father')
}
function Son() {
}
// 原型对象继承
// 方法1. 直接将我们的Father.prototype赋值给Son.prototype(即可拿到Father.prototype上的init方法)
// Son.prototype = Father.prototype
// 方法2. 遍历Father.prototype 看看原型上边有哪些方法, 将所有方法添加到Son.prototype
for (const key in Father.prototype) {
Son.prototype[key] = Father.prototype[key]
}
var father = new Father()
var son = new Son()
console.log(father, son)
</script>
</body>
</html>
