Good Practice: modular JavaScript

When we all begin with JavaScript we start writing big-ass files, all the functions on the same place, hoping we’ll never have to edit again. It’s basically: “good luck future me if you have to debug this thing”. Hundreds of lines and chaos.

Well, there’s a better way to do things. Let’s use a modular approach, we’ll create components and call them as necessary.

common.js

Here we’ll place all the calls to components. Something like this:

/components/navigation.js

So, on our common.js we’ve called the init() function for the navigation component. Let’s see what’s inhere:

We’ll make use of the $that approach inside our components.

How do you handle your JavaScript?

In those projects where you’re not using things like AngularJS, how do you work with plain JavaScript code?

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*