JS 组合继承
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.eat = function () {
console.log("eat方法")
}
function Teacher(name, age, type, classNum) {
Person.call(this, name, age);
this.type = type;
this.classNum = classNum
}
Teacher.prototype = new Person();
Teacher.prototype.constructor = Teacher;
Teacher.prototype.do = function () {
console.log("备课")
}
var teacher1 = new Teacher("haijing", 40, "html5", 0223);
console.log(teacher1)
console.log(teacher1.eat)
console.log(teacher1.constructor)
</script>
</body>
</html>