从另一个“班级”调用功能/文件 [英] Call functions from another "class" / file

查看:85
本文介绍了从另一个“班级”调用功能/文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我感到很尴尬,我无法自己弄清楚这一点,但在浪费了几个小时后,我觉得简单地问一下这里会比较容易:



我的Google Apps脚本项目中有一堆.gs文件。现在,我想从一个方法调用另一个文件的函数(类似于 AnotherClass.awesomeFunction(),它引发一个 ReferenceError 虽然)。这在Google Apps脚本中可能吗?如果是这样,怎么样?

解决方案

文件不是类。您可以从任何其他文件中调用任何文件中的任何函数。想想你的文件,就好像它们只是在运行之前一起加入。如果您想要类似范围的范围,您可以使用库功能。


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?

解决方案

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.

这篇关于从另一个“班级”调用功能/文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆