I experimented with this some years ago, building my own mini-framework for components. The main system provided a global hook that javascript within the template file could attach itself to, so everything for a single component did exist in a single file. So it is doable.
(I liked that part of my system, but I'd rewrite about half of it if I wanted to use it again)
(I liked that part of my system, but I'd rewrite about half of it if I wanted to use it again)