strange problem with closures

strange problem with closures


Edge rails has a feature :cache - where it will concatenate all your
javascript files into one all.js
However when I did this I found that it mattered where I put various
plugins. - and errors would be thrown. Needless to say I put jquery.js
first. E.g. I wrapped rating,js in a closure thus :
(function($){
$.fn.rating = function(url, options) {
etc..
    })(jQuery);
If it occured just after image_search.js, which ended :
ImageSearch.buttonAction = function(query) {
loadScript("http://search.yahooapis.com/ImageSearchService/V1/
imageSearch?appid=" + YAHOO_APP_ID + " &query=" + query +
"&results=20&output=json&callback=ImageSearch.YahooCallback" )
}
It would throw a weird error which looked somewhat like I was trying
to call a function on $.fn.rating
I fixed it by including rating.js just after jquery.js - but it seemed
very strange.
*...(