I write different parsers of the HTML context of an event in a webpage.
The basic structure goes like this:
registering the event and link it to a parser function.
elem.addEventListener(
'click',
(e) => {
let parser = new UiResultsItemInfoParser(e);
eventInfo = parser.evntInfo;
submitEvnt(eventInfo);
}
);
UiResultsItemInforParser is a sub-type of a super type called EvntParser and e obviously is the event object.
EvntParser looks like this:
function EvntParser (e) {
this._evntInfo = {};
this._evntInfo.time = e.timeStamp.toString();
this._evntInfo.type = 'event';
}
EvntParser.prototype = {
set evntInfo(e) {
this._evntInfo.time = e.timeStamp.toString();
this._evntInfo.type = 'event';
},
get evntInfo() {
return JSON.stringify(this._evntInfo);
}
};
UiResultsItemInforParser is derived from EvntParser and looks like this:
function UiResultsItemInfoParser(e) {
EvntParser.call(this, e);
}
UiResultsItemInfoParser.prototype = new EvntParser();
UiResultsItemInfoParser.prototype.constructor = UiResultsItemInfoParser;
Unfortunately, I get TypeError: e is undefined for the line this._evntInfo.time = e.timeStamp.toString(); in EvntParser when the event is triggered and a new UiResultsItemInfoParser object is created in addEventListener.
Why is that and how can I fix it in a way that EvntParser has access to the event object during object creation?