WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?

What you need is the function_exists method

you would use it like this when defining your returnJs function:

if( ! function_exists('returnJs') ){
    function returnJs(){
        //Code goes here
    }
}

However, better practice would be to just define the returnJs function in your plugin