Why Nostr? What is Njump?
2024-05-09 13:03:52

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)?
Author Public Key
npub1r6ju958fxhaelfm9ze5gl039zhtywp8wjwkr406pnzc45yjnwmnq6m40lw