SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Location
    Dubrovnik, Croatia
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery plugins - objects question

    Hi to all

    I have a question regarding jQuery plugins. I have found jQuery plugin and i was analyzing code i and there i saw this :

    Code:
    ;(function($) {
    $.fn.extend({
            test: function() {}
    });
    
    $.NameofClass = function() {
    }
    
    })(jQuery);
    What exactly is $.NameofClass why dot? Can someone explain please

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    $.NameOfClass is an alternative way to name a plugin function name. The other way is $.fn.NameOfClass. Both are frequently done together because they offer slightly different functionality, mostly because of the scope they expose themselves in.

    Code javascript:
    $('#foo .bar').doStuff(); // do something to a DOM element
    var stuff = $.doStuff(); // do something without a DOM element as context
    Sometimes the function doesn't have to operate on a DOM element but can do other things, like make measurements. In this case the $.NameOfClass way is useful. Some native jQuery functions work like this, e.g. most of the ajax stuff.

    See this article for a better example.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Location
    Dubrovnik, Croatia
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your answer, that explains a lot. One more thing is there a documentation on extending jquery?

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes. It's the first result if you'd bothered to google "extending jquery".


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •