Need help deciphering JQuery example

Posted by chobo on Stack Overflow See other posts from Stack Overflow or by chobo
Published on 2011-01-29T23:10:23Z Indexed on 2011/01/29 23:26 UTC
Read the original article Hit count: 192

Filed under:

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:

  1. Why is (function surrounded by () ?
  2. What does this mean (jQuery.subclass()); ? Is this a JQuery thing or part of regular javascript?

Thanks

© Stack Overflow or respective owner

Related posts about jQuery