0

I have some repeatable functions created with jQuery I want to reuse. I could write them in functions(), but another one I'm seeing is a plugin in the form of

jQuery.fn =

so I'm not sure if I should write functions or use the plugin form, what is the difference? The code within my function is rather large, should I then use the plugin form?

1
  • How should your function be used? One is a "jQuery plugin" and one is not .. the length of code itself does not matter. (In the end they are all "just JavaScript functions".) Commented Aug 24, 2012 at 23:46

2 Answers 2

1

The main advantage of jquery plugins is portability. It lets you build a structure that is more easy to use and maintain. Please refer to this article for other benefits:
http://james.padolsey.com/javascript/why-create-a-jquery-plugin
It depends on what you are building. For example, if there is no re-use, you might consider going for functions.
If you need a good article on creating plugins - please refer to this:http://james.padolsey.com/javascript/why-create-a-jquery-plugin.
Please consider other options as well. I like to use the Microsoft Ajax library and build a set of 'objects'.

Sign up to request clarification or add additional context in comments.

Comments

0

Read this http://docs.jquery.com/Plugins/Authoring for more infos about the .fn from jQuery.

In your case i'd guess you can simply use normal plain JS functions because you don't write a plugin ;)

Comments

Your Answer

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.