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 :


;(function($) {
$.fn.extend({
        test: function() {}
});

$.NameofClass = function() {
}

})(jQuery);

What exactly is $.NameofClass why dot? Can someone explain please

$.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.

$('#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.

Thank you for your answer, that explains a lot. One more thing is there a documentation on extending jquery?

Yes. It’s the first result if you’d bothered to google “extending jquery”.