title: Alternative to JavaScript `with` statement when generating DOM elements
body: <p>Say, I have a JavaScript library to produce a DOM fragment like the following</p>
  
  <pre><code>&lt;main&gt;
    &lt;h1&gt;A heading&lt;/h1&gt;
    &lt;p&gt;A paragraph&lt;/p&gt;
  &lt;/main&gt;
  </code></pre>
  
  <p>where the library, <code>domlib</code>, has methods for any type of element, and a function generating the fragment above could look like this:</p>
  
  <pre><code>function(domlib){
    return domlib.main(
      domlib.h1('A heading'),
      domlib.p('A paragraph')
    );
  }
  </code></pre>
  
  <p>Within this function I would rather like to call the <code>domlib</code> methods like this:</p>
  
  <pre><code>main(
    h1('A heading'),
    p('A paragraph')
  )
  </code></pre>
  
  <p>To achieve this, I could place all the methods of <code>domlib</code> in the global scope, but I would rather avoid to pollute the global scope. To me, this appears to be a case where the <code>with</code> statement would have been an ideal solution:</p>
  
  <pre><code>function(domlib){
    with(domlib){
      return main(
        h1('A heading'),
        p('A paragraph')
      );
    }
  }
  </code></pre>
  
  <p>Although still supported, <a href="https://stackoverflow.com/a/48811296/6738706">the <code>with</code> statement is practically deprecated</a>, and will <a href="https://stackoverflow.com/q/48810592/6738706">throw an error in strict mode</a>.</p>
  
  <p>I do not see many other options, except to assign <code>domlib</code> methods to local function variables, but that would easily result in assigment of dozens of local variables, in which case the first approach (calling methods on <code>domlib</code> directly) would lead to simpler code.</p>
  
  <p>My question is, <em>is there any other alternative to achieve what I want</em>, with similar simplicity and readability as using a <code>with</code> statement?</p>