title: How to create "svg" object without appending it?
body: <p>Consider the following code:</p>
  
  <pre><code>var svg = d3.select('#somediv').append("svg").attr("width", w).attr("height", h);
  </code></pre>
  
  <p>I would like to refactor this code so that it reads more like this:</p>
  
  <pre><code>var svg = makesvg(w, h);
  d3.select("#somediv").append(svg);
  </code></pre>
  
  <p>Note that, in contrast to the situation shown in the first version, in this second version <code>append</code> <em>does not create</em> the "svg" object; it only appends it to <code>d3.select("#somediv")</code>.</p>
  
  <p>The problem is how to implement the function <code>makesvg</code>.  This in turn reduces to the problem: how to instantiate an "svg" object without using <code>append</code> to do this, since one could then do something like:</p>
  
  <pre><code>function makesvg(width, height) {
    return _makesvg().attr("width", w).attr("height", h);
  }
  </code></pre>
  
  <p>So my question boils down to what is the generic equivalent of the hypothetical <code>_makesvg()</code> factory mentioned above?</p>