Try sticking a js object in a patch and get help on it . . ..
In these you will find what you need to know, there is even a globalvar example patch . . .
Thanks for the answers
@Macciza I did know a little bit about the global variables, but I thought that they were "variables", not functions, that´s the reason why I asked. But surely I missed something in the documentation, I'm quite new with js and scripting in general.