This is most likely an issue w/ Babel, and may be related to this issue, but I wanted to post this to see if someone might be able to help me.
Say I have the following classes defined:
A = class A {
constructor(value, options) {
this.value = value;
this.options = options;
console.log('constructor this: ', this);
}
get value() {
return this._value;
}
set value(value) {
this._value = value;
}
get options() {
return this._options;
}
set options(options) {
this._options = options;
}
get validationErrors() {
// Do standard validations for all classes of type A here
console.log('A.validationErrors this: ', this);
var validationErrs = [];
if (options && options.required && !value) {
validationErrs.push('Value is required');
}
return validationErrs;
}
}
B = class B extends A {
get validationErrors() {
console.log('B.validationErrors this: ', this);
var valErrs = super.validationErrors;
// Do custom validations for class B here
return valErrs;
}
}
var b = new B('val', {required: true});
var valErrs = b.validationErrors;
Furthermore, if I call this.value or this.options in the parent's validationErrors, I end up with undefined returned. It seems like the constructor and getters are being copied down, at least in behavior, but they shouldn't be, right? I would think that the child's constructor would simply call the parent's in this case, but that doesn't seem to be happening.
This is most likely an issue w/ Babel, and may be related to this issue, but I wanted to post this to see if someone might be able to help me.
Say I have the following classes defined:
Strangely, what I see in the logs is:
Furthermore, if I call
this.value
orthis.options
in the parent'svalidationErrors
, I end up with undefined returned. It seems like the constructor and getters are being copied down, at least in behavior, but they shouldn't be, right? I would think that the child's constructor would simply call the parent's in this case, but that doesn't seem to be happening.