Why is the dat.gui instance type so long and nested?

dat.gui seems to be a relatively simple javascript library. So why, when you instantiate it, it returns dat.GUI.dat.gui.GUI.GUI?

instantiating dat.gui

EDIT: I think I'm not explaining myself badly here. This is a QUESTION - apparently, the authors of dat.gui did not want to do this, but for some reason they had to be angry like crazy. Can downvoters please give some criticism so that I know what I'm doing wrong here?

EDIT, still trying to explain myself: I need an answer that puts this in the context of javascript style and conventions. Is this just bad code? Is there any reason that a prototype-based language leads to an additional type of nesting? Is dat.gui in order to do much more than I understand, and is it actually used for dat.GUI.dat.gui?

0
source share
1 answer

The type name is not long and nested after all - in fact it is anonymous. Combining an unusual coding style with the quirk of Chrome Dev Tools makes it the same as him. This does not happen in Firefox.

On line 1532 of the dat.gui.js file, a prototype dat.GUI is created, which I created using new dat.GUI() , and dat.gui.GUI also assigned:

dat.GUI = dat.gui.GUI = (function ...

This feature is anonymous. When Chrome Dev Tools prints a view of an anonymous function that has been assigned to a variable, it pretends that the variable name is the name of the function for debugging convenience.

For some reason, which is discussed but not fully explained in this question , Chrome combines these function aliases in the case when you assign an anonymous function to several properties of an object

enter image description here

So why

dat.GUI = dat.gui.GUI = (function ...

prints

function dat.GUI.dat.gui.GUI()

in Chrome Dev tools.

0
source

All Articles