Xin chào.
Đoạn code này là dùng để kế thừa lớp Person cho lớp student.
Bạn nào giải thích cho mình cách thực hiện đc ko ạ
T ko hiểu vai trò và tác dụng 2 dòng này
Person.call()
Và
// Tại sao cần dòng này ạ?
Student.prototype = new Person();
function Person(firstName, lastName) {
this.FirstName = firstName || "unknown";
this.LastName = lastName || "unknown";
}
Person.prototype.getFullName = function () {
return this.FirstName + " " + this.LastName;
}
function Student(firstName, lastName, schoolName, grade)
{
Person.call(this, firstName, lastName);
this.SchoolName = schoolName || "unknown";
this.Grade = grade || 0;
}
//Student.prototype = Person.prototype;
Student.prototype = new Person();
Student.prototype.constructor = Student;
var std = new Student("James","Bond", "XYZ", 10);
alert(std.getFullName()); // James Bond
alert(std instanceof Student); // true
alert(std instanceof Person); //