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
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/d3cab6d3-8623-45d9-aff3-35eddb4c37bbn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAHNYQLgsAu_ihE1xFheAE0h412U1i8FuMLM2J8mKkEnA4kd1PA%40mail.gmail.com.