I basically having hard times understanding why I cannot overwrite an object property when using inheritance from another object, it goes like this.
var Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
Object.defineProperties(Person.prototype, {
sayHi : {
value :function() {
return "Hi there";
},
enumerable : true,
writable : true
},
fullName : {
get : function() {
return this.firstName + " " + this.lastName;
},
enumerable : true
}
});
var createEmployee = function(firstName, lastName, ocupation) {
var employee = new Person(firstName, lastName);
employee.ocupation = ocupation;
Object.defineProperty(employee, "sayHi", {
sayHi : {
value : function() {
return "Hey I am " + this.firstName;
}
}
});
return employee;
};
var janeDoe = createEmployee('Jane', 'Doe', 'Actress');
So, accoding to what I understand, I should overwrite the sayHi property on the employee object, however, I get it as undefined.
Could please some1 show me money?
here is the jsfiddle
Best Regards.