using brackets with javascript import syntax

import React, { Component, PropTypes } from ‘react’; This says: Import the default export from ‘react’ under the name React and import the named exports Component and PropTypes under the same names. This combines the two common syntaxes which you’ve probably seen import React from ‘react’; import { Component, PropTypes } from ‘react’; The first … Read more

How to return many Promises and wait for them all before doing other stuff

You can use Promise.all (spec, MDN) for that: It accepts a bunch of individual promises and gives you back a single promise that is resolved when all of the ones you gave it are resolved, or rejected when any of them is rejected. So if you make doSomeAsyncStuff return a promise, then: const promises = … Read more

Javascript ES6 computational/time complexity of collections

Right from that very paragraph your linked to: Set objects must be implemented using [mechanisms] that, on average, provide access times that are sublinear on the number of elements in the collection. You will find the same sentence for Maps, WeakMaps and WeakSets. It looks the ECMA spec mandates that the implementations (e.g. Set.prototype.has) are … Read more

How to clone a javascript ES6 class instance

It is complicated; I tried a lot! In the end, this one-liner worked for my custom ES6 class instances: let clone = Object.assign(Object.create(Object.getPrototypeOf(orig)), orig) It avoids setting the prototype because they say it slows down the code a lot. It supports symbols but isn’t perfect for getters/setters and isn’t working with non-enumerable properties (see Object.assign() … Read more

How to extend Function with ES6 classes?

The super call will invoke the Function constructor, which expects a code string. If you want to access your instance data, you could just hardcode it: class Smth extends Function { constructor(x) { super(“return “+JSON.stringify(x)+”;”); } } but that’s not really satisfying. We want to use a closure. Having the returned function be a closure … Read more

What’s the difference between babel-preset-stage-0, babel-preset-stage-1 etc?

Babel’s stage presets equate to the TC39 Process and the different states of each proposal for a potential language change. They include implementations and polyfills for all of the proposed changes in that stage. Anything currently in Stage-0 is Strawman, not ES6. It is future Javascript and absolutely not certain that it will ever make … Read more