[eluser]davidbehler[/eluser]
Basically you got two options:
1. You can add a "[removed][removed]" tag to your view and insert your js function there or
2. Put your function in a js file and include that file in your view using "[removed][removed]"
If the code of your function depends on the data that was loaded, e.g. the id of an element you work on, then you can't put it in a js file but have to put it in your view and fill all the parts that are variable using <?=?>.
Correct me if I am wrong, but that's what I have been doing so far and I could not come up with anything else that seemed more appropriate. (Except that you can create your js code in the controller and give it to the view file using the $data array)