'ES6 module constructor's scope

I've stumbled upon a behavior I cannot understand. Could someone, more proficient with JS, have a quick glance at it.

I apologize for posting screenshots instead of setting up a working example here, but I hope it should be enough for an expert to quickly recognize what's reason is.

  • I have a JS class in an ES6 module
  • I pass a function to the class' constructor
  • I attach an event handler to an HTMLElement and in this handler I expect to have this function to be accessible.

It's accessible if I don't use ES6 modules, I've checked. So the reason must be related to the ES6 modules' scope also I suspect the shadow DOM may be related.

So at this point, line 8 the notifyController function is definedpicture of a browser's console window, function is defined.

But when the event handler is run, it's undefined.picture of a browser's console window, function is not defined

How come?

Thank you in advance.


Solved:

The reason turned out to be that the View constructor was called twice. Many thanks to @Bergi who suggested that this was a possible reason.

One time manually with expected parameters, in a module file. The other time automatically w/o expected parameters, because the html contained a custom element to which this class was assigned.

Put short: the reason was inappropriate use of custom elements


I'd prefer to leave the question here, in case anyone else has a similar problem



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source