Word about JS, modules and alike

Shit

This just sums up pretty nicely.

Real-life example

Say you are tasked with creating a tick module. Seems pretty simple? Well, up to compiling stage.

Code & samples

cullay.js

exports.module = {
    // Module name here, like "testModule". If you have multiple  modules you'd like to export, just name them all here.
}

Now let's call this module from another file:

import * from testModule;

That will import (make available) every exported structure within the module testModule. Pretty simple.

Now, if testModule has any submodules, we can import them (JS is so shitty that it doesn't import them by default).

// Either (remove space betwen / and *
import */ * from testModule;

// or
import { submod1, submod2... } from testModule;

Scumbags like jQuery handle it differently:

${'module'}.forEach(load(this.module));

Either way, you have to specify in package.json

(...)
type: "module"

Then try to run your code. Here is what you get:

Cannot use import statement outside a module

That's fucked up!