Javascript Code Organization

Hello,
I am finding myself doing a bunch of stuff over and over like creating event listeners and then using those event listeners to make AJAX calls using jquery $.ajax function. Within those ajax calls depending on the outcome I create different modals that pop up using sweet alert 2. I’m writing all of this procedurally and it’s just taking up a ton of space and I’m essentially re-writing the same stuff over and over with only minor modifications. SOOOO it seems to me like I should be using OOP to reduce duplication but I’m struggling to find resources that show me how to write code for those use cases. Does anyone have suggestions / resources that I can look at so I can stop writing duplicate code and start writing reusable stuff?

PS I know the basics of OOP from a theoretical point of view, but I find it challenging to incorporate those in to the real world of web dev.

I think javaScript modules might be what you’re after?

It allows you to create modules which you can import and export to other scripts.

Have a look at MDN here for more information MDN - Javascript Modules

And check out their examples repo for some implementation examples. GitHubRepo

Hope this helps.