Roma Komarov on Nostr: Let's say I want to have a web component. Whenever I use it, I would like to provide ...
Let's say I want to have a web component.
Whenever I use it, I would like to provide a custom callback to run in its context, defining it in HTML.
Is there an idiomatic way to do so? The way I'm thinking of is to use `currentScript`:
<my-element>
<script> document.currentScript.myCallback = () => console.log('Hey!');</script>
</my-element>
And then call this `myCallback` from inside the `connectedCallback`.
Is there anything better (apart from using a unique `id` for this)?
Whenever I use it, I would like to provide a custom callback to run in its context, defining it in HTML.
Is there an idiomatic way to do so? The way I'm thinking of is to use `currentScript`:
<my-element>
<script> document.currentScript.myCallback = () => console.log('Hey!');</script>
</my-element>
And then call this `myCallback` from inside the `connectedCallback`.
Is there anything better (apart from using a unique `id` for this)?