So let’s say i’m building a huge website, something close to facebook size, and i’m using jquery for most of the client side stuff, now obviously there is probably going to be at least 4k lines of code and thousands of ajax request etc..
So my question is fairly simple, what is the best way to build my jquery based scripts, should i create plugins for things that im going to use multiple times or should i just use functions and call them whenever i need?
EDIT Well maybe i overdid it with facebook size but it’s going to be pretty big anyways..
A plugin or function can accomplish the task just fine either way. A plug-in makes sense if you have an operation that operates on one or more DOM objects like other jQuery methods.
A plug-in has the advantage that you can chain it more easily as in:
And, it’s a way to create a number of functions in the jQuery namespace without using the global namespace at all. Other than that, there isn’t a whole lot of difference between it and a function.
If you have a commonly used jQuery operation, then there is no downside to making it a plug-in and you gain the ability to chain method calls.