标签:pre struct alert let call xtend end js继承 cto
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.sayName = function () {
alert(`My name is ${this.name}.`);
return this.name;
}
Person.prototype.constructor = Person;
function Student(name, age, grade) {
Person.call(this, name, age);
this.grade = grade;
}
Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;
Student.prototype.sayGrade = function () {
alert(`I am a grade ${this.grade} student.`);
return this.grade;
}
let s1 = new Student("Mike", 12, 4);
let s2 = new Student("Helen", 18, 12);
class Person {
constructor (name, age) {
this.name = name;
this.age = age;
}
sayName () {
alert(`My name is ${this.name}.`);
return this.name;
}
}
class Student extends Person {
constructor (name, age, grade) {
super(name, age);
this.grade = grade;
}
sayGrade () {
alert(`I am a grade ${this.grade} student.`);
return this.grade;
}
}
let s1 = new Student("Mike", 12, 4);
let s2 = new Student("Helen", 18, 12);
标签:pre struct alert let call xtend end js继承 cto
原文地址:https://www.cnblogs.com/buildnewhomeland/p/13123907.html