JavaScript
Create a new file my.js
(function (global, factory) {
(factory(global.MY_OBJECT = {}));
}(this, (function (exports) {
var a = 8;
function ShowValue(val)
{
alert(val);
}
// exports
exports.b = 10;
exports.ShowValue = ShowValue;
})));
Html
Create a new file test.html
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<meta charset="utf-8">
</head>
<body>
<!-- loading the library my.js -->
<script src="my.js"></script>
<script>
MY_OBJECT.ShowValue(23);
// on the screen we will see 23
</script>
</body>
</html>
This principle is used by the library
Three.js
JavaScript
File Three.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.THREE = {})));
}(this, (function (exports) { 'use strict';
...
exports.CanvasRenderer = CanvasRenderer;
exports.SceneUtils = SceneUtils;
exports.LensFlare = LensFlare;
})));