Hacker News new | past | comments | ask | show | jobs | submit login

Would it be possible to use the Custom Elements API [1] to wrap the evalFromTo() function as a custom element?

If we define a custom element like:

  class PrintOutput extends HTMLElement {
    constructor() {
      super();
      const templateNode = document.getElementById(this.getAttribute('from'));
      if (templateNode) evalFromTo(templateNode, this);
    }
  }
  
  customElements.define('print-output', PrintOutput);
Then instead of calling the evalFromTo() function:

  <div id=counterout></div>
  <script>
    evalFromTo(document.querySelector('#counterapp'), document.querySelector('#counterout'));
  </script>
We could simply use the <print-output> custom element:

  <print-output from=counterapp></print-output>
[1]: https://developer.mozilla.org/en-US/docs/Web/Web_Components/...



Great idea. I will try it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: