I was writing a global javascript function. And after some mistakes (and a few searches here) I got it to work. But I also saw an example with (function($){ code here
}(jQuery);
what is the difference (if any) and is there any advantage between option 1 and 2? both perform my task well. I am just trying to learn the difference.
OPTION #1
(function($){
TEAM={
getQB: function( success, failure) {
var user=USER.user_data.login.toUpperCase();
$.ajax({
type: "GET",
url: "/nfl/getQB?username="+user,
dataType: 'json',
async: false,
success: success,
error: failure,
timeout: 6000
});
},
getRB: function( success, failure )
{
userx=USER.user_data.login.toUpperCase();
$.ajax({
type: "GET",
url: "/nfl/getRB?username="+userx,
dataType: 'json',
async: false,
success: success,
error: failure,
timeout: 6000
});
}
}
})(jQuery);
OPTION #2
var TEAM={
getQB: function( success, failure) {
var user=USER.user_data.login.toUpperCase();
$.ajax({
type: "GET",
url: "/nfl/getQB?username="+user,
dataType: 'json',
async: false,
success: success,
error: failure,
timeout: 6000
});
},
getRB: function( success, failure )
{
userx=USER.user_data.login.toUpperCase();
$.ajax({
type: "GET",
url: "/nfl/getRB?username="+userx,
dataType: 'json',
async: false,
success: success,
error: failure,
timeout: 6000
});
}
}