An alternative to ES6 module


Module is a new feature of ES6, which is very convenient for large projects to call modular functions.
But in the use of found that if only a simple call HTML5 do not use node.js There will be cross domain problems.
An alternative to ES6 module
As an alternative, it can be simply edited lib.js Just encapsulate it instead of using the module method
So how to achieve it?

  1. open lib.js
  2. Comment out export/ Object.defineProperty …
  3. Add var at the beginning [ keyword ] = function () {
  4. Add} ()
  5. Return returns the variable / method to be used
  6. stay index.js Use [keyword] directly in

In this way, the problem of polluting variables will not appear
Simple and convenient, clean and sanitary