Since I learned how to write my own plugins in jQuery, I find I'm tempted to approach my javascript that way any time I'm building a page with any complexity to it. Obviously it's silly when we're talking about 10 lines of code, but when I'm going to be building a page with a couple hundred lines of javascript (or more), it seems the easiest way to:
$("#myform").myPagePlugin({options}, {data});
Am I digging myself into a hole if I start doing this? Is there something I'm missing?
My only critique would be that you're creating a jQuery plugin it seems you are never really planning on using again. This adds the overhead of running the JavaScript that jQuery runs to initialize a plugin when that overhead is not worth it, since the module will never be used again.
Instead of a jQuery plugin, why don't you create a JavaScipt object which is namespaced? For example:
var mypage = {};
mypage.controller = function(){
} //your preferred JavaScript object notation here.
Or is this namespaced approach what you are refering to as "hacky"? If so, I would respectfully disagree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With