Call functions from another "class" / file

Well, I am confused by the fact that I could not understand it myself, but after several hours wasted, I realized that it would be easier to just ask here:

I have a group of .gs files in my Google Apps Script project. Now I want to call another file function from a method (something like AnotherClass.awesomeFunction() , which throws a ReferenceError though). Is this possible in Google Apps Script? If so, how?

+6
source share
3 answers

Files are not classes. You can call any functions in any file from any other file. Think of your files as if they were added together before running. If you want to classify by class, you can use the Libraries function.

+13
source

It can be done.

and Corey is right, files are not classes.

See below code:

https://script.google.com/d/1QcyrlnwWGdMnJNxJ2X4qfGeM1q75YxJopPuNKUDgOjmqsp4dilLYtC-A/edit

+1
source

The following syntax allows you to call any function from your Google Apps Script project, regardless of whether the function is defined in the same file that calls it:

 myFunction(); 

The following code is not needed and will cause errors:

 google.script.run.myFunction(); 
0
source

Source: https://habr.com/ru/post/919707/


All Articles