为什么会输出今年男岁了而不是12岁,难道实参要按顺序写吗
<!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.sex = sex; this.age = age; }; People.prototype.sayHello = function () { console.log('你好,我是' + this.name + ',我今年' + this.age + '岁了'); } People.prototype.sleep = function () { console.log(this.name + '正在睡觉'); } function Student(name, sex, age, school, sid) { People.call(this, name, sex, age); this.school = school; this.sid = sid; }; Student.prototype = new People(); Student.prototype.exam = function () { console.log(this.name + '正在考试'); } Student.prototype.sayHello = function () { console.log('敬礼!你好,我是' + this.name + ',我今年' + this.age + '岁了,我是' + this.school + '的学生'); } var xiaoming = new Student('小明', '男', 12, '小慕学校', 100066); xiaoming.sayHello(); xiaoming.sleep(); xiaoming.exam(); </script> </body> </html>
6
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星