We talk a lot about the idea of having bootstrap files in WordPress plugins, which I think are great, but we seem to limit it to those files that are responsible just for starting our WordPress plugins.
When it comes to working with WordPress, you’re more than likely going to be working with jQuery.
- It’s a tried and true library,
- It ships with core,
- The UI library is available so that you can take advantage of other elements, as well.
And sure, this isn’t to discount the use of other libraries like Backbone, but when it comes to working with DOM manipulation on both the client-side and the server-side you’re less likely to use Backbone (and more likely to use jQuery).
But this still doesn’t answer the question:
And here’s an example of what I’d like to avoid:
Obviously, I’ve left out the method implementation, but I’ve tried to make the point clear enough. There should be functions each of which have a responsibility, and they should call other functions they need when they need them.
The ready handler just invokes whatever function or functions should fire as soon as the DOM is ready. This ultimately makes the code that has so much potential to be difficult to read a bit easier to follow, to document, and to trace.
In a future post, I’ll talk about separating the files and then combining them into a single file during the build process as that will take the benefits of this idea even further.