Skip to content

Instantly share code, notes, and snippets.

@CITguy
Last active July 17, 2019 22:18
Show Gist options
  • Save CITguy/a7a440531a72d6f0577bf075a0ed8e71 to your computer and use it in GitHub Desktop.
Save CITguy/a7a440531a72d6f0577bf075a0ed8e71 to your computer and use it in GitHub Desktop.
Web Platform

The Web Platform

A collection of resources for developing native web apps.

HTTP

HTML

CSS

JavaScript

Import/Export

Single File:

// constants.js
export const FOO = 'FOO';
export const BAR = 'BAR';

// Importing and Using

// Option 1
import * as constants from './constants';
let myValue = constants.FOO;

// Option 2
import { FOO, BAR } from './constants';
let firstValue = FOO;
let secondValue = BAR;

Multiple Files:

/*
 * my_lib/index.js
 * my_lib/sub1.js (exports sub1)
 * my_lib/sub2.js (exports sub2)
 */

// some_dir/index.js
export { default as sub1 } from './sub1';
export { default as sub2 } from './sub2';

// IMPORT & USE

// OPTION 1
import { sub1, sub2 } from './some_dir';
sub1.doStuff();
sub2.logThings();

// OPTION 2
import * as myLib from './my_lib';
myLib.doStuff();
myLib.logThings();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment