title: How can I use d3 classed selection to have name as function
body: <p>I am using <a href="https://github.com/d3/d3-selection#selection_classed" rel="nofollow noreferrer">d3 classed selections</a> and in first parameter, instead of a string, I want to use a function that will returns class name.</p>
  
  <pre><code>selection.classed(name[, value])
  </code></pre>
  
  <p>I understand I can do the same using <code>.attr()</code> as mentioned <a href="https://stackoverflow.com/questions/11420568/d3-js-tree-layout-how-to-name-classes-using-a-function">here</a>, but I want to be able to do the same using classed.</p>
  
  <p>How can I do this?</p>