i am buliding an autocomplete for my website when i came across this style of building code:
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$(element).autocomplete(....
//more code
});
i know about closures, "IIFE"s but this one's a new one for me.
- what's with the "jQuery-wrapped" code above?
- is there any particular reason i should do that? (scope?)
- optimization-wise, should i even do it that way?