You can reuse same HTML fragments on multiple places of your UI. Just remember one new html attribute XJ-CONTROL:
Your can simply define SCRIPT tag inside of your control and put interaction scripts inside. Mark element by attribute XJ-NAME to access it directly as a private field:
Functions added to "root" instance becomes to public methods of control. These methods could, inter alia, act as setters, connected to HTML attributes:
And, using star as a first symbol in event hadnling expression, events handling inside of control is easy:
Also building contianer controls is easy, using tag <XJ-CONTENT /> as a place holder.
For buildng of more complex controls you might find useful Control Templates