I\'m delving into writing plugins for jQuery and I\'m trying to understand the distinction between $.f and $.fn.f
I\'ve seen pluggin authors use both, or sometimes a
The $.f
is a utility function whereas $.fn.f
is a jQuery plugin / method.
A utility function is basically a function within the jQuery namespace that is useful for performing some operation, for example, $.isArray(obj)
checks if an object obj
is an array. It is useful to put functions in the jQuery namespace if you'll use them often and also to avoid global namespace pollution.
jQuery methods on the other hand operate on jQuery objects/wrapped sets. For example, Hello$(document.body).append('
will append a paragraph containing Hello to the body element of the document. $.fn
is a shorthand for $.prototype
in later versions of jQuery (it wasn't always in earlier versions of the library). You would use this when writing your own plugins.