GAS:从绑定脚本中调用在加载项中定义的函数吗? [英] GAS: Calling functions defined in an add-on from bound script?

查看:43
本文介绍了GAS:从绑定脚本中调用在加载项中定义的函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经为电子表格编写了google app脚本代码.我想将它的一部分作为附件发布,另一部分(保留为绑定到电子表格的脚本)应该能够调用该加载项中的函数.
我没有在Google文档中找到关于此的任何提示.
我阅读了如何在库中调用函数.插件中的调用函数是否相似?
原因是我想隐藏附加代码的逻辑,但让用户可以自由更改非附加代码.


I have written google app script code for a spreadsheet. I want to publish part of it as an add-on, the other part (which stays as script bound to the spreadsheet) should be able to call functions in that add-on.
I didn't find any hint in the google documentation about this.
I read how calling functions in a library. Is calling functions in an add-on similar?
Reason behind is I want to hide the logic of the add-on code, but give users the freedom to change the non add-on code.

推荐答案

无法从附加组件内部调用函数.

There is no way to call functions from inside an Add-On.

但是,图书馆的文档提到了如何创建方法和私有属性,在最佳做法"部分下,第3号.

However, the documentation for Libraries mentions how to make methods and properties private, under the Best practices section, number 3.

您可以使用这些方法在Java和其他语言上创建类似于 private 封装的结构,在这些语言中,您具有私有方法和属性,然后具有允许用户操纵它们的公共方法.

You can use these methods to create a structure similar to private encapsulation on languages like Java and others, where you have private methods and properties and then public methods that allow users to manipulate those.

如果您使用库调试项目,您将能够以只读方式浏览库中的代码.

If you debug a project with libraries, you will be able to browse the code on the libraries as read-only.

虽然这是预期的结果,但由于其他语言也有此结果(如果您正在调试Java代码,即使没有提供源代码,您仍然可以看到JVM方法标头和堆栈跟踪.),没什么可做的.

While that is an expected result, since other languages also have it (if you are debugging a java code, even if there is no source provided, you can still see the JVM method headers and the stack-trace.), there is not much to be done.

但是,您可以使用一种巧妙的方法来混淆代码:

However, you can use a clever method to obfuscate your code:

考虑发布一个Web应用程序,该应用程序将接收您计划处理的数据并与之交互,而不是通过Apps Script的 UrlFetchApp .

Consider publishing a web app that receives the data you plan on manipulating and interact with that instead with Apps Script's UrlFetchApp.

您还可以制作一个库来隐藏"您正在从非调试用户处调用Web应用程序的事实(毕竟,他们将能够看到您的代码).但是您的隐藏"代码是安全的.

You can also make a library to "hide" the fact that you are calling an web app from your non-debugging users (after all, they would be able to see your code). But your "hidden" code would be safe.

这篇关于GAS:从绑定脚本中调用在加载项中定义的函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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