htmlhammer icon indicating copy to clipboard operation
htmlhammer copied to clipboard

When customElement provider parameter is passed a class, non-custom-element methods seem to be lost

Open zruzak opened this issue 3 years ago • 0 comments

When customElement provider parameter is passed a class, non-custom-element methods seem to be lost.

Demonstration:

const yetiCustom = customElement(
  'yeti-custom',
  new (class {
    SomeObj = {
      someProp: 0
    };
    aField = 'a field';

    connectedCallback() {
      console.log(this.SomeObj.someProp);
      console.log(this.aField);
      this.SomeLog();
    }

    SomeLog() {
      console.log('some log');
    }
  })()
);

this.append(yetiCustom());

console:

0
a field
Uncaught TypeError: this.SomeLog is not a function
....

Bonus: the provider can't be passed simply as a class, but an instance has to be passed.

zruzak avatar Feb 20 '23 10:02 zruzak