class Something {
a() {
}
get b() {
return "bValue"
}
}
Something.prototype.eef = "dfd";
window.someValue = "parent value";
/*
*/
Object.defineProperty(Something.prototype,"abc",{
enumerable:true,
configurable:true,
get:function(){
debugger;
return "parent value";
},
set : function(value){
debugger;
window.someValue=value;
}
});
class Derived extends Something {
get b() {
return "inside child bValue"
}
}
class Derived1 extends Something{
};
/*
obj1=new Derived1();
obj1.abc. should be "parent value"
*/
case 1: setting property abc in Derived class
Derived.prototype.abc="child value";
/* obj2=new Derived();
obj2.abc should be "child value" but getting "parent
value"
*/
case 2: setting property abc in Derived class using Object.defineProperty
Object.defineProperty(Derived.prototype,"abc",{
value:"child value",
enumerable:true,
configurable:true
});
/* obj3=new Derived();
obj3.abc output is "child value" which is expected
*/
I am defining property on Derived class directly using the above two method. I am expecting that when I create an object (obj=new Derived()) for both the cases and try to get abc property of class. Then I should get the same value ie. "child value" . But for my implementation I am somehow triggering the getter and setter defined on "abc" in parent class "Something" prototype which is not normal and because of this I am getting two different value for the two cases.The thing which I am not getting is how I can make changes to the prototype of parent through child.