For the below code
// Parent constructor function
function Person(name, age, gender){
this.name = name;
this.age = age;
this.gender = gender;
};
//Child constructor function
function Employee(name, age, gender, empId){
// Is this the right way ?
Person.call(this, name, age, gender);
this.empId = empId;
};
//Inherit the properties from Parent
Employee.prototype = Object.create(Person.prototype);
// Fix the inherited constructor
Employee.prototype.constructor = Employee;
john = new Employee('John', 21, 'male', 213);
console.log(john.hasOwnProperty('empId')); // true
// Shoudn't this be false
console.log(john.hasOwnProperty('name')); // true
// Shouldn't the above statement work similar to this one
console.log(john.hasOwnProperty('toString')); // false
My question is how do we pass name, age, gender to Person constructor in ES5?
What is the right way to do it ?
Update:
If the above is right then why is console.log(john.hasOwnProperty('name')); // true
. Should'nt this be false ?