Q:

How to access a class through its object literal's variable?

Say I have a simple class:
class Folder {
   constructor() {
      this.title = "a folder";
      this.dropdownInstance = {
         element: document.createElement("div")
      }
   }
}

and I store the element of dropdownInstance somewhere in my DOM.
Say another Object has an EventListener on that element, and that object wants to access Folder, is it possible to do so?
Basically going from element -> dropdownInstance -> Folder which holds its dropdownInstance

A:

To achieve this you will need some type of referencing system. This is what jQuery allows with the data method to attach arbitrary data to DOM elements.
I would probably use a simple array:
const folders = [];

class Folder {
    constructor(){
        this.title = "a folder";

        this.dropdownInstance = {
            element: document.createElement("div")
        }

        folders.push([this.dropdownInstance.element, this]);
    }

    static getFromElement(el) {
        const folder = folders.find(f => f[0] === el);
        return folder ? folder[1] : null;
    }

}

You could then simply call Folder.getFromElement(el) to retrieve the Folder instance.

