Skip to content

Instantly share code, notes, and snippets.

@jkrems
Last active August 29, 2015 14:02
Show Gist options
  • Save jkrems/df0add317718dfbce51a to your computer and use it in GitHub Desktop.
Save jkrems/df0add317718dfbce51a to your computer and use it in GitHub Desktop.
How to write ES6 modules
export function each() {}
export function map() {}
export function reduce() {}
export function isEmpty() {}
export function extend() {}
export default function _() {}
extend(_, {each, map, reduce, isEmpty, extend, _, default: _});
@jkrems
Copy link
Author

jkrems commented Jun 24, 2014

Cases handled:

// returns an object with all methods
import _ from './my-module';

// after going through different ES6 compiler implementations, this could
// safely read [[exports]].default
import _ from './my-module';

// import individual exports
import {each, reduce} from './my-module';

// import all, destruct later
import _ from './my-module';
let { each, reduce } = _;

// import all when you also want the default export
import { _, each } from './my-module';
_(myValue).map(x => each(x, y => y * 2));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment