Where to define functions

Josh Willing:
EDIT: i think i found the answer here: https://docs.fmbetterforms.com/usage/javascript-tips/calculations#as-a-function.
Beginner question: where is the appropriate place to define a page-scoped pure helper function. For example:

displayName(name: string): string {
  if (name === 'PUSH_INVOICES') return 'Push Invoices'
  else if (name === 'SINGLE_INVOICE') return 'One Invoice'
  else return name
}

and i’d like to be able to call it within the page schema components like {{displayName(someValue)}}

BTW is this the right place to ask this type of question or is discourse better?


Delfs:
you can define it in a few palces, doesnt matter too much as long as you bind it to window

I often add functions the the DOM insertions as it is in window by default and global.

Alternate places are onAppLoad - but a refresh of the page can call it before it’s defined

in on the pages onFormLoad - it will be available before page renders.


Josh Willing:
Got it. I was wondering if binding to window was right approach. Thx.


Delfs:
Here is fine, we will push to the folmrun if useful!