Call functions from another “class” / file

2020-05-26 12:07发布

Ok, I feel embarrassed that I wasn't able to figure this out on my own, but after a few wasted hours, I figured it would be easier to simply ask over here:

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

3条回答
We Are One
2楼-- · 2020-05-26 12:28

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

myFunction();

The following code is unnecessary and will throw errors:

google.script.run.myFunction();
查看更多
贼婆χ
3楼-- · 2020-05-26 12:29

Files aren't classes. You can call any functions in any file from any other file. Think of your files as if they were just added together before running. If you want class-like scoping you can use the Libraries feature.

查看更多
聊天终结者
4楼-- · 2020-05-26 12:38

It can do.

and Corey is right, files is not class.

Please see below code:

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

查看更多
登录 后发表回答