GAS: Calling functions defined in an add-on from bound script?

戏子无情 提交于 2021-02-05 12:12:41

问题



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.


回答1:


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

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

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.

What about debugging?

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

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:

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

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.



来源:https://stackoverflow.com/questions/58682542/gas-calling-functions-defined-in-an-add-on-from-bound-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!