It seems to work by adding a pair or parentheses for a function:
b.onClick = helloDocument();
Assigning the function itself is intended here.
Your suggestion would invoke it once and assign the result.
In the meantime I found that if I launch my script via File/Scripts menu the #targetengine directive will do its duties.
I only had tried via startup script, assuming I would need some more unknown code to set up a menu entry, matching InDesign's scriptable menus.