创建运动员的实例'谁是一个“人”。

时间:2017-01-11 16:53:20

标签: javascript

我正在尝试使下面的代码工作,以便我可以创建一个' mary'谁是运动员'谁是“人物”。谁能指出我在这里做错了什么?

var Person = function(name, age, sex) {
  this.name = name;
  this.age = age;
  this.sex = sex;
}

var Athlete = function(name, age, sex, sport) {
  this.prototype = new Person(name, age, sex);
  this.sport = sport;
}

Person.prototype.describe = function() {
  console.log('This is ' + this.name + ' and he is a ' + this.age + ' year old ' + this.sex + '.');
};

var john = new Person('John', 23, 'male');

var mary = new Athlete('Mary', 18, 'female', 'running');

john.describe();
mary.describe();

提前感谢您的帮助:)

0 个答案:

没有答案