Skip to content

Commit

Permalink
Improve docs on function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
iansan5653 authored Feb 22, 2024
1 parent c5289e8 commit 54788e9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,24 @@ to the engine. In the traditional Google Apps Script environment, you'd do this
functions, however in this setup there is no concept of 'global' as all files are modules.

Instead, all (and only) functions exported from `index.ts` will be available to Google Apps Script.
Any function added to the `global` object will be available= to all
Any function exported from `index.ts` will be accessible by all
[triggers](https://developers.google.com/apps-script/guides/triggers) and anywhere else Google Apps
might need to call your function, such as from a
[custom menu](https://developers.google.com/apps-script/guides/menus).

Examples for all the simple triggers are given in
[`index.ts`](https://github.com/iansan5653/gas-ts-template/blob/master/src/index.ts#L39-L43).
[`index.ts`](https://github.com/iansan5653/gas-ts-template/blob/master/src/index.ts).

For cleaner, more usable code, it may be useful to reference functions by their `name` property instead of hardcoding the name into code.
For example:

```ts
const createButton = CardService.newTextButton()
.setText("Create")
.setOnClickAction(CardService.newAction().setFunctionName(onClickCreateEvent.name)); // instead of "onClickCreateEvent"
.setOnClickAction(
// Here we use `onClickCreateEvent.name` instead of hardcoding `"onClickCreateEvent"`
CardService.newAction().setFunctionName(onClickCreateEvent.name)
);
```

### Circular Dependencies
Expand Down

0 comments on commit 54788e9

Please sign in to comment.