Questions about $function operator

Hello

Some questions about $function operator

1)Is it possible to make an enviroment that $function code will see when executes?
($function accepts only 1 function)

2)Where to save the javascript?sending the javascript inside the command is the best way? or i need to save it in some collection i saw system.js
but i dont know if it works with $function,and if it has perfomance benefits

Thank you