View file.js
function f() {
function g() {

Why .mjs

Alternative 1

As far as I can tell from the latest update, the ability to import ES6 import from CommonJS modules is off the table. The main argument for this was to enable existing modules to upgrade to ES6 without causing any breakage to their CommonJS dependants.

This is a big deal. This means that CommonJS libraries that want to upgrade to ES6 modules will HAVE to bump semver-major version to

View translate-error.js
function translateError(msg) {
var newErr = new Error(msg); // placed here to get correct stack
return e => {
newErr.originalError = e;
throw newErr;
async function asyncTask() {
const user = await UserModel.findById(1).catch(translateError('No user found'))
View mobx-form-prototype.ts
type ValidationError = string | boolean | null;
function fNoError<T>(t:T):ValidationError { return null }
class FieldState<TField> {
private validator: (val:TField) => ValidationError = fNoError
@observable focused = false
@observable changed = false
@observable finisedEditing = false;
View typescript-2.1-json.ts
type Json = null | boolean | string | number | Array<{}> | {}
function tArray<T>(f:(t:any) => t is T) {
return function (a:any): a is Array<T> {
if (!Array.isArray(a)) return false;
for (var k = 0; k < a.length; ++k)
if (!f(a[k])) return false;
return true;
View 01-mobx-async-magic.ts
import {render} from 'react-dom'
import {observable, computed, action} from 'mobx'
import {observer} from 'mobx-react'
import * as React from 'react'
import {fromPromise, IPromiseBasedObservable} from 'mobx-utils'
import 'whatwg-fetch'
import {computedAsync, matchAsync} from './computed-async'
function delay<T>(n:number) {
View pinger-promises.js
import _ from 'lodash';
import fetch from 'node-fetch';
import delay from 'delay';
function pingServers(servers) {
let last = Promise.resolve();
let results = => last = last.then(() => {
let failures = Promise.resolve(0)

The code

export default function getLikes () {
  return new Promise((resolve, reject) => {
    getUsers().then(users => {
      .catch((err) => {
View promise-variables.js
function getData() {
var respondent = Respondent.findById(respondentId)
var box = respondent.then(r => Box.findById(r.box_id))
var user = box.then(box => User.findById(box.owned_by))
return Promise.props({user, box, respondent})

Async-sync correspondence

Just like typical expressions are evaluated at time of assignment, promise expressions are also evaluated eagerly.

Promise values act like regular values. You can reuse regular variable values later:

var x = someExpression()

// some other method or function, later: