Questions tagged [ecmascript-2016]

Questions about new features specified in the ECMAScript 2016 specification.

This tag targets ECMAScript 2016, a JavaScript standard previously known as ECMAScript 7. Any proposal that reached stage 4 by Jan 28th, 2016 became part of the new version.

These are:

484 questions
11
votes
2 answers

Make sure that using this pseudorandom number generator is safe here

When I declared a variable like: const FileId = Math.random().toString(36).substr(2, 9); I am getting this error in Sonar: Make sure that using this pseudorandom number generator is safe here. How should I address this? What is wrong with my…
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
11
votes
1 answer

Class decorators in ES7

I've been reading up on decorators in JavaScript, and think I'm getting the basic premise. Decorators are functions, they receive as a or several parameters what they should decorate, and return the result. But I came over a @withStyles decorated…
SomeNorwegianGuy
  • 1,494
  • 4
  • 17
  • 43
11
votes
3 answers

Module Build Failed - Webpack, React, Babel

I was following a video tutorial from plural sight. Course name is "Building a Real-time App with React, Flux, Webpack, and Firebase". Please see below code and attached screen shot of the issue i am having. Webpack is failing when ever i try to re…
Erkan Demir
  • 785
  • 1
  • 8
  • 24
11
votes
5 answers

react-dnd simple sortable example ES6 instead of ES7

I'm attempting to follow this example: https://github.com/gaearon/react-dnd/tree/master/examples/04%20Sortable/Simple But the code is using ES7 and I don't know how to replace the decorators and the decorate dependency in this…
Recur
  • 1,418
  • 2
  • 17
  • 30
11
votes
2 answers

Using a Decorator to get list of implemented interfaces

Do you know if it is possible to get the array of interfaces implemented by a class using a decorator: interface IWarrior { // ... } interface INinja { // ... } So If I do something like: @somedecorator class Ninja implements INinja, IWarrior…
Remo H. Jansen
  • 23,172
  • 11
  • 70
  • 93
10
votes
3 answers

How to "multicast" an async iterable?

Can an async generator be somehow broadcast or multicast, so that all its iterators ("consumers"? subscribers?) receive all values? Consider this example: const fetchMock = () => "Example. Imagine real fetch"; async function* gen() { for (let i…
P Varga
  • 19,174
  • 12
  • 70
  • 108
10
votes
1 answer

How to merge and return new array from object in es6

Suppose there are two objects. const a = [ { id: '1-1-1', name: 'a111' }, { id: '1-1-2', name: 'a112' }, { id: '1-2-1', name: 'a121' }, { id: '1-2-2', name: 'a122' }, { id: '2-1-1', name: 'a211' }, { id: '2-1-2', name: 'a212' } ] const b…
SPG
  • 6,109
  • 14
  • 48
  • 79
10
votes
1 answer

ES7 Classes: Declaring Properties Outside of Constructor

Is there any difference between declaring variables inside the constructor vs. outside? For functions, 'this' is bound differently, but for variables, I cannot figure out if there is a difference. class Widget { constructor(constructorName) { …
M. Walker Wells
  • 151
  • 2
  • 7
10
votes
1 answer

Typescript Object destructuring results in "Property assignment expected."

I am transitioning a project from Babel to Typescript and receive the following compiler error: error TS1136: Property assignment expected. from code that looks like this: var auth = {...this.props.auth}; This code previously worked fine under…
Rick
  • 8,366
  • 8
  • 47
  • 76
10
votes
1 answer

NodeJS 5.x + Babel 6 async/await debugging

I'm having spotty debugging experiences when I try to debug code with async/await using transform-async-to-generator babel plugin ( although I've tried almost every other combination ). Essentially code with a await will skip to the end of the…
amcdnl
  • 8,470
  • 12
  • 63
  • 99
10
votes
1 answer

Node exits before async function completes

I have a function that returns a promise, and I am trying to await on it from within an async function. The problem is that the program completes immediately, instead of awaiting the promise. async-test.js: function doItSlow() { const deferred =…
Dan Ross
  • 3,596
  • 4
  • 31
  • 60
9
votes
4 answers

Function similar to Promise.some/any for an unknown amount of promises

I am creating a script in node.js (V8.1.3) which looks at similar JSON data from multiple API's and compares the values. To be more exact I am looking at different market prices of different stocks (actually cryptocurrencies). Currently, I am using…
Manu Masson
  • 1,667
  • 3
  • 18
  • 37
9
votes
2 answers

SyntaxError: Unexpected token static

I'm currently trying to evaluate different testing frameworks that work with React, and it turns out that Jest is on my list. However, I'm trying to use static properties outlined here:…
HappyCry
  • 873
  • 2
  • 9
  • 16
9
votes
2 answers

How to avoid hard coded this? in Decorators

I have read "How to implement a typescript decorator?" and multiple sources but there is something that i have nor been able to do with decorators. class FooBar { public foo(arg): void { console.log(this); this.bar(arg); } …
Remo H. Jansen
  • 23,172
  • 11
  • 70
  • 93
8
votes
1 answer

JavaScript exponentiation unary operator design decision

So I was fooling around with the new exponentiation operator and I discovered you cannot put a unary operator immediately before the base number. let result = -2 ** 2; // syntax error let result = -(2 ** 2); // -4 let x = 3; let result = --x ** 2;…