Different ways to define private function in Google App Script Libraries?

Viewed 28

I have a Web App I want to use as a library for another script I am writing and it will eventually be semi-public. I have made most of my relevant internal functions private the only way I know how - by appending an underscore to the function name.

However, this doesn't work for special reserved function names such as onOpen or onEdit. I know it's quite nitpicky of me, as anyone attempting to run these functions will just get errors anyway, but just curious if there is a way to specify these functions as private so they don't appear in the calling editor's auto-complete?

1 Answers

If you are using the default runtime, V8, instead of using

function onEdit(){

}

use

const onEdit = () => {

}

  • Apply the same any for any other simple trigger that you want to hide, as onOpen, onSelectionChange, doGet and doPost.
  • Instead of const you might use let, but do not use var.
  • Instead of () => {} y you might use function () or the name of a private function i.e. myFunction_ (note that the parenthesis aren't included).
Related