// The module patternvarfeature= (function(){ // Private variables and functionsvarprivateThing="secret";varpublicThing="not secret";varchangePrivateThing=function(){privateThing="super secret";};varsayPrivateThing=function(){console.log( privateThing );changePrivateThing();}; // Public APIreturn{publicThing:publicThing,sayPrivateThing:sayPrivateThing};})();feature.publicThing;// "not secret"// Logs "secret" and changes the value of privateThingfeature.sayPrivateThing();
export const aString = 'test'
export function aFunction(){
console.log('function test')
}
export const aObject = {a: 1}
export class aClass {
constructor(name, age){
this.name = name
this.age = age
}
}
import {aString, aObject, aFunction, aClass} from './lib.js'
console.log(aString)
console.log(aObject)
import * as myModule from './lib.js'
console.log(myModule.aString)
console.log(myModule.aObject)
myModule.aFunction()
const newObj = new myModule.aClass('Inori', 16)
console.log(newObj)
function aFunction(param){
return param * param
}
export default aFunction
import aFunction from './lib2.js'
console.log(aFunction(5))
import square from './lib2.js'
console.log(square(5))
export var x = 42; // export a named variable
export function foo() {}; // export a named function
export default 42; // export the default export
export default function foo() {}; // export the default export as a function
export { encrypt }; // export an existing variable
export { decrypt as dec }; // export a variable as a new name
export { encrypt as en } from 'crypto'; // export an export from another module
export * from 'crypto'; // export all exports from another module
import 'jquery'; // import a module without any import bindings
import $ from 'jquery'; // import the default export of a module
import { $ } from 'jquery'; // import a named export of a module
import { $ as jQuery } from 'jquery'; // import a named export to a different name
import * as crypto from 'crypto'; // import an entire module instance object