Motivation
It’s good practice to keep class and namespace definitions in separate files and avoid defining functions or variables in the global space. However, App Script doesn’t give you control over the order in which it loads files. If you reference a class or a namespace from one script file, it may not yet be defined. This is where an Exports object comes in.
Using ‘var’ rather ‘const’ can help, as JavaScript var ‘hoists‘ both var and function declarations, but this won’t always solve the problem, especially with class definitions.
Many of my projects have 20 or more files and I kept running into this problem until I figured out this simple workaround. You also create a much cleaner, better documented and more flexible project.
Here’s how to use an Exports object which documents the contents of your script
Exports
You can solve this visibility problem by using an Exports obects, where you define property getters for each of your classes and namespaces.
Here’s an example of an Exports variable for a complex project with many files.
Why does using exports work ?
You can ensure the visibility of the Exports object by using var to hoist the object to ensure it’s visible to the other files.
Using property getters postpones the attempt to access the definition.
JSDOC
What about JsDoc ?
You’ve probably documented each class and namespace diligently, and you want autocomplete to still work, even when wrapped in an Exports object like this.
The @implements {} directive takes care of this for you, and autocomplete information will be inherited from the referenced class.
Complex and library definitions
You can extend this further to implement library references, or other more complex definitions in Exports object.
This means you won’t need to change your main scripts if you, for example, flip from using inline code for testing to a library in production. You can even test a renamed variant of an existing function, or use this technique to avoid naming clashes
Find me here
Related
State management across CardService, HtmlService and Server side Add-ons

Caching, property stores and pre-caching

State management across CardService, HtmlService and Server side Add-ons

SuperFetch Plugin: Cloud Manager Secrets and Apps Script

Apps script caching with compression and enhanced size limitations

12 Years and 1000 pages in Office,Google (Docs,Gsuite) Workspace, and other stuff

Import, export and mix container bound and standalone Apps Script projects
Apps Script server side to client side htmlservice progress reporting using CacheService

Sharing data between Apps Script and Node using Google Drive back end – 5 minute example
