5

I have seen a few different approaches to create jQuery(-namespaced) functions, but I cannot quite tell the actual difference between them.

jQuery.fn.myFunction = function() { ... };

jQuery.myFunction = function() { ... };

jQuery.fn.extend({ myFunction: function() { ... } });

asked Dec 2, 2010 at 11:20

1 Answer 1

6

jQuery.fn.myFunction is what you use to create functions that will be available on every jQuery result set:

$('div').myFunction();

jQuery.myFunction is what you use to create helper functions that are just available on the jQuery object, such as $.inArray

Your last version extends the $.fn object with a new function, and is as such the functional equivalent of your first example.

answered Dec 2, 2010 at 11:24
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.