请问这俩添加的原型,是添加到了哪里,是添加到了构造函数People身上吗

<!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 People(name, age, sex) {
this.name = name;
this.age = age;
this.sex = sex;
};
People.prototype.sayHello = function () {
console.log('我是' + this.name + ',我今年' + this.age);
};
People.prototype.sleep = function () {
console.log(this.name + '开始睡觉');
};
// 子类
function Student(name, age, sex, school, id) {
this.name = name;
this.age = age;
this.sex = sex;
this.school = school;
this.id = id;
};
// 实现继承
Student.prototype = new People();
Student.prototype.study = function () {
console.log('我正在学习');
};
Student.prototype.exam = function () {
console.log('我正在考试');
};
var hanmeimei = new Student('韩梅梅', 20, '女');
hanmeimei.sayHello();
hanmeimei.sleep();
</script>
</body>
</html>15
收起
正在回答
1回答
同学你好,同学理解是对的,祝学习愉快~

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星