0
1

More than 3 years have passed since last update.

JavaScript Modules CommonJS, EM, ES2015

Posted at

CommonJS

Used in node.js

mod.js
exports.foo = () => {}
app.js
const mod = require("mod")
mod.foo()

AMD (Asynchronous Module Definition)

define(['jquery'] , function ($) {
    return function () {};
});

ES2015(ESCMA6)

foo.js
export const a = {} // `equals exports.a = {}` of CommonJS
// or 
module.exports = {a: {}}
app.js
import {a} from foo // `equals const a = require("foo").a` of CommonJS
// or
import * as foo from "foo"
const a = foo.a

refs

  1. https://addyosmani.com/writing-modular-js/
  2. https://auth0.com/blog/javascript-module-systems-showdown/
  3. https://requirejs.org/docs/whyamd.html
  4. https://2ality.com/2014/09/es6-modules-final.html
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1