Global functions at the Collection level

How can I use global function (which receives parameters) in the Collection level (either in the Pre-Request or Tests section) and afterwards call the function from the request?
I tried implementing it, and it failed. Got error that the function is not defined.

old school solution:

…in collection pre-req:
postman.setGlobalVariable(“foo2Function”, () => {

// do your stuff here

});

…in test:
foo2 = eval(pm.globals.get(“foo2Function”));

foo2();