I have the fowlling mixins, with a setter and a getter:
const dataentity_compnts_mixins = {
set within_context(val_obj) {
switch (val_obj["dataentity_morphsize"]) {
case 'compact':
this.shadow_wrapper.setAttribute(
"within-context", "compact_dataentity");
break;
case 'expanded':
this.shadow_wrapper.setAttribute(
"within-context", "expanded_dataentity");
break;
}
},
get within_context() {
const host_dataentity = this.parent_dataentity ||
this.closest('independent-data-entity') ||
this.closest('dependent-data-entity');
this.parent_dataentity = host_dataentity;
const context_dict = {
"dataentity_morphsize": host_dataentity.getAttribute("morph-size"),
"dataentity_role": host_dataentity.getAttribute("entity-role")
};
return context_dict;
}
};
then I use Object.assign to merge this into my custom element's prototype:
Object.assign(IndividualviewEditor.prototype, dataentity_compnts_mixins); [1]
I was expecting that the getter and the setter won't be evaluated until being called with this refering to the host object, which in my case is the IndividualviewEditor custom element. However, when run this code on my webpage, I got an error:
Uncaught TypeError: this.closest is not a function ...
I checked the callstack, which suggests that the getter is being called by the line [1].
I've done many searches on google and totally lost. This getter is evaluated when being merged into my prototype?? this is much earlier than I expected.