There are a couple of issues here:
person2.prototype = new person()
is wrong way of inheritance ( More on that here )
It should be
person2.prototype = Object.create(person.prototype);
person2.prototype.constructor = person2;
person.prototype.getfullName should be declared outside of person constructor function. Otherwise, every instance created using new will update the method on the prototype
(Reference: here, here and here)
function person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
person.prototype.getfullName = function() {
return `${this.firstName} ${this.lastName}`
}
The first argument to the .call is the this value to be used inside the person function. So, it should be
person.call(this, firstName, lastName)
Here's the updated snippet:
function person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
person.prototype.getfullName = function() {
return `${this.firstName} ${this.lastName}`
}
function person2(firstName, lastName, age, location) {
person.call(this, firstName, lastName)
this.age = age;
this.location = location;
}
person2.prototype = Object.create(person.prototype);
person2.prototype.constructor = person2;
let result = new person2('nivedhan', 'kumar', 24, 'neyveli')
console.log(result.getfullName())
console.log(result.age)