I have this piece of code
let person=new Object({
fname: 'Uday',
sname: 'Kiran',
getFName: function(){
return this.fname;
}
});
Object.defineProperty(person,'getSName',
{
value: function(){return this.sname;},
writable: false,
enumerable: true,
configurable: true
});
let personInherited=Object.create(person);
This is possible, I'm able to override getSName property with the help of Object.defineProperty eventhough it is defined as writable: false in person.
Object.defineProperty(personInherited,'getSName',
{
value: function(){
return this.sname.toUpperCase();
},
writable: true,
enumerable: true,
configurable: true
});
But I'm not able override the getSName property like below.
personInherited.getSName=function(){
return this.sname;
}
Can someone please explain what is the difference between creating a property by using Object.defineProperty and directly assigning property using personInherited.getSName