meleyal
meleyal

Reputation: 33240

jQuery - application code vs making a plugin

When does it make sense to turn your code into a jQuery plugin?

What are the criteria / signs that parts of your code might be better as plugins?

Upvotes: 3

Views: 117

Answers (2)

scragz
scragz

Reputation: 6690

It is more than anything a matter of if the code is at all abstrable/reusable at all and if so, if you think you will actually need to be reusing it at any point in the near future. I generally end up with a mixture of both; common functionality abstracted into plugins, and page-specific custom code intializing those plugins and setting up whatever is unique to that page.

I know exactly what you mean about where to make the decision to abstract it and there are no hard and fast rules to follow. If it isn't completely obvious, you can at least try to write the custom code with an eye to the future that you might be making it into a plugin. Javascript really makes that easy with its closures.

Upvotes: 2

ThiefMaster
ThiefMaster

Reputation: 318478

Actually, your code is a jQuery plugin as soon as you start adding new stuff to $.fn.

But besides that, it makes sense for reusable code or code which is not specific to your application.

Also have a look at the Plugin Authoring Guide - it shows you some best-practices you should follow; especially if you might release your jquery plugin at some point. But it might also give you some ideas about when it makes sense to make your code a plugin.

Upvotes: 2

Related Questions