Answer the question
In order to leave comments, you need to log in
What is the correct way to refer to the setter of the parent class in the child in JavaScript?
If I declare a property in the prototype of the parent class, in the following way:
Foo.prototype = {
get target() {
return this._target;
},
set target(value) {
this._target = value;
}
}
Answer the question
In order to leave comments, you need to log in
Yes, the only one. Yes, costly. If you don't like it, cache the parent descriptor.
var P = {
set a(it){
console.log('P');
}
}
var C = {
__proto__: P,
set a(it){
a.set.call(this, it);
console.log('C');
}
}
var a = Object.getOwnPropertyDescriptor(P, 'a');
C.a = 42;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question