Your assertion that loading a file that simply defines a function will solve the problem is a bit too simplistic for most web applications.
Could you describe the case where wrapping script in a function would not solve the problem in UAs that parse scripts asynchronously?
-- regards, Kornel Lesiński