In response to mbostock's block: Local Variables and the Tweet I implemented a little variation having a .local(name[, value)
method you can use on selections.
On set, the value is stored on the given element:
element.local("foo", value);
On get, the value is retrieved from given element, or the nearest ancestor that defines it:
var value = element.local("foo");
https://d3js.org/d3.v4.0.0-alpha.44.js