Need help deciphering JQuery example
- by chobo
I just started learning JQUery and OO Javascript, so I am trying to figure out which belongs to which and what they do. I came across this code in the JQuery documentation
(function($sub) {
$sub // a subclass of jQuery
$sub === jQuery; //= false
$sub.fn.myCustomMethod = function(){
return 'just for me';
}
$sub(document).ready(function() {
$sub('body').myCustomMethod(); //= 'just for me'
});
})(jQuery.subclass());
Questions:
Why is (function surrounded by () ?
What does this mean (jQuery.subclass()); ? Is this a JQuery thing or part of regular javascript?
Thanks