I am still using an old version (1.3.2) of FancyBox (a lightbox) and I am trying to understand the basics of this code.
The usage is:
$(".myClass").fancybox({
'property1' : value,
'property2' : value
});
And the source code is like this:
;(function($) {
// Some declarations and code
$.fancybox = function(obj) {
}
// Some code
})(jQuery);
I don't quite understand this syntax. Why does it start with a semicolon? I assume an extended method of jQuery is being created here. Maybe someone can explain or point me the way to an explanation.
It is a self invoking function.
Self-Invoking function is a type of function that is invoked or called automatically after its definition when followed by the parentheses set () and primarily used for the initialization tasks. This write-up demonstrated the syntax and usage of self-invoking functions in JavaScript to wrap the code inside a function scope.
Adding a semicolon at that time was considered "good practice" to avoid problems with concatenation of multiple files.