I have created two constructor Person and Employee. Employee construct inheriting the property of Person. This working fine. Now I want to add new property in Person constructor with prototype. But getting blank string. Please help.
JS Code
function Person (age, weight) {
this.age = age;
this.weight = weight;
}
Person.prototype.name = name;
//we will give Person the ability to share their information.
Person.prototype.getInfo = function () {
return "I am " + this.age + " year old and weight " + this.weight + " kg.";
};
function Employee (age, weight, salary, name) {
//Person.call(this, age, weight); // by call parameters as arguments
Person.apply(this, arguments); // by apply arguments as array
this.salary = salary;
}
Employee.prototype = new Person();
Employee.prototype.constructor = Employee;
Employee.prototype.getInfo = function () {
return "I am "+this.name+" " + this.age + " year old and weight " + this.weight + " kg having $" + this.salary +" pm salary";
}
var person = new Employee(30, 70, 4000, "Manish");
console.log(person.getInfo());
document.write(person.getInfo());