为什么会输出今年男岁了而不是12岁,难道实参要按顺序写吗
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <!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积分~
来为老师/同学的回答评分吧