I have created objects and prototypes in ES5, now I want to create a new prototype which will group existing object, I have this code
const person = function(firstName,lastName){
this.firstName =firstName;
this.LastName = lastName;
this.getFullName = function () {
return firstName + ' ' + lastName ;
};
this.setFullName = function(firstName, lastName) {
firstName = firstName.split(' ')[0];
lastName = lastName.split(' ')[1];
};
};
I created a student prototype that is an extension of the person class
const student = function(firstName,lastName, grade ) {
person.call(this, firstName, lastName);
this.Averagegrade = grade;
};
const group = function(Title, firstName,lastName, grade ) {
this.Title = Title;
person.call(this, firstName, lastName);
student.call(this, grade);
const addstudent = Object.create(person);
return firstName + ' ' + lastName ;
};
group.__proto__ = student;
const john = new student('Jack','Sparrow', '53');
john.setFullName('Jack', 'Sparrow');
const group1 = new group( "group1");
group1.addstudent(john);
console.log(group1);
but I keep getting this as output
group {
Title: 'group1',
firstName: undefined,
LastName: undefined,
getFullName: [Function (anonymous)],
setFullName: [Function (anonymous)],
Averagegrade: undefined
}