score:1

Accepted answer

The var root is set where it calls a function (classes), but when that function is defined it is passing in the root object.

No, it simply has a parameter that is named root. This has nothing to do with the root variable outside of the function.

You could rename the function parameter for example foobar (function classes(foobar), and inside recurse(null, foobar);), and things would still work exactly the same.

score:0

Your confusion is completely understandable, considering there are two uses of root, and they don't refer to the same thing.

Note that classes is invoked by classes(data), so the root in the classes function refers to the data loaded in flare.json, while the root in your data loading function is a d3 object, returned by d3.hierarchy.

I would recommend renaming the root parameter in classes so there's less confusion.


Related Query