←back to thread

367 points lemonberry | 1 comments | | HN request time: 0.214s | source
Show context
sam_goody ◴[] No.24642768[source]
If there was a way to write JS within the component, I think that they could have taken off - just see how well components are in React, Vue et al.

And to get that to happen, all you would need is the ability to refer to `this` within the component. Aside for that, treat the JS within the component as a module, ability to access global vars, but within scope.

But instead, you are expected to put the relevant JS in the code that creates the component (in the parent document), which means that reusability and is a pipe dream, and components are really not componentized.

replies(2): >>24646817 #>>24647958 #
1. megous ◴[] No.24646817[source]
You don't need to add anything to the global JS object to create a web component. It can be completely isolated and untouchable from the document's scope, except for registering a html name for the component, so that you can reference it from DOM/HTML.