Re: [WICG/webcomponents] Constructor arguments in custom elements (#605)

As it wasn't said here :

- If you want to have constructor arguments, they all need to have a default value, and instead of using `createElement()` you can :

````javascript
let elem = new (customElements.get('my-custom') )("foo", "faa", "fuu")
````

- If your element is in HTML, just use the html attribute in the `connectedCallback()` to initialize your element.

- If you want to bind arguments to a tag name :

````javascript
class MyCustom extends HTMLElement {
     constructor(foo = null) {   }
}

function bindCstr(custom, ...args) {
             class X extends custom {
                constructor() {
                    super(...args)
                }
             }

             return X;
       }

customElements.define(name, bindCstr(MyUI, 'foo') );
````

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/605#issuecomment-1751640342
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/605/1751640342@github.com>

Received on Saturday, 7 October 2023 07:46:48 UTC