Re: [WICG/webcomponents] [element-internals] How to get internals in base class and subclass, without leaking it to public (Issue #962)

@keithamus But in your example, if a subclass of the base class doesn't need the internals (not all end subclasses may need them) then your example leaves the extra call available for the public.

The following is still a problem, isn't it?

```js
customElements.define('my-el', class extends HTMLElement {})
document.createElement('my-el').attachInternals() // returns "internals" to the public. (I had expected an error)
```

I originally thought that `attachInternals` could only be called in `constructor`. It would be enforceable with `documet.createElement`, but not with `new` unless the DOM engine can do something special with the JS engine that otherwise normal JS users can't.

And, if `attachInternals` would be callable only in `constructor` (otherwise throw), then we could as well rename it to `getInternals` and allow it to be called any number of times in `constructor`.

So, if we can't actually guarantee that `attachInternals` is internal (unless explicitly leaked by an author), why call it `attachInternals`?

Maybe it should be called `attachFeatures` or `getFeatures` because it is clearly public, just throws on any call other than the first (this does not at all guarantee privacy or "internal"ness).

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

Message ID: <WICG/webcomponents/issues/962/1198634020@github.com>

Received on Thursday, 28 July 2022 21:10:29 UTC