Echo JS 0.11.0

<~>

tracker1 2746 days ago. link 2 points
Not ES6, but with async/await, I tend to put this in the top of quite a few of my files, easier as a oneliner than pulling in from a library module a lot of the time.

    const sleep = ms => new Promise(res => setTimeout(res, ms));
olalonde 2731 days ago. link 1 point
Another one relatively simple:

    const promisify = fn => (...args) => new Promise(resolve, reject) {
      fn(...args, (err, result) => {
        if (err) return reject(err)
        resolve(result)
      }
    }
MaxArt 2746 days ago. link 1 point
Actually the object spread operator is part of ESNext, so no need to bring JSX up. And it's *so* much better than Object.assign to create immutable objects.
Basically,

    const foo = { ...bar };

is equivalent to

    const foo = Object.assign({}, bar);

but the former is more compact and readable than the latter.