// Object Literal
var MyModule = {
property: 'someValue',
method: function () { }
};
// Module Pattern
var Module = (function () {
// Private state
var privateVar,
privateMethod;
privateMethod = function() { };
// Public state
return {
publicVar: 'someValue',
publicMethod: function() { }
};
})();
// app.js
var App = {};
// Code goes here
window.App = App;
// overlay.js
function Overlay() { }
App.Overlay = new Overlay();
// importing
require(['react', './doSomething'], function(React, doSomething) {
// Code goes here
});
// exporting
define('Overlay', ['react'], function(React) {
function Overlay() { }
return new Overlay();
});
// importing
const React = require('react');
const doSomething = require('./doSomething');
// exporting
function Overlay() { }
module.exports = new Overlay();
// overlay.js
(function (global, factory) {
if (typeof define === "function" && define.amd) {
// AMD
define(["react", "./doSomething"], factory);
} else if (typeof exports === "object") {
// CommonJS
module.exports = factory(
require("react"),
require("./doSomething"));
} else {
// Globals
global.Overlay = factory(global.React, global.doSomething);
}
}(this, function (React, doSomething) {
var Overlay = function () { };
return Overlay;
}));
// importing
import React from 'react';
import doSomething from './doSomething.js';
// exporting
function Overlay() { }
export default new Overlay();