Hey there, I came across some intriguing posts on this topic, but I believe it's a very personal question that requires a tailored answer. So, I'm reaching out to ask you: what is the most effective way to organize my code for a JavaScript plugin in the most unobtrusive manner?
This is how my current code looks:
var myApp = (function(){
// Here are my global methods or variables
var self = this;
return {
method1:function(){}
method2:function(){}
method3:function(){}
}
})() || (myApp = {})
myApp.method1();
I am executing 'method1', which calls or uses the entire code of my app. I think I could add an 'onload' event with the `addEventListener` method to execute 'method1'. This way, I believe my code could be better organized. Just to clarify, my plugin is relatively small - around 200 lines of JavaScript code - and must be implemented in VanillaJS. It is used on a single page of a website, so I don't see the necessity of creating a prototype class called with "new," in my opinion.