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
648
votes
25 answers

How can I clone a JavaScript object except for one key?

I have a flat JS object: {a: 1, b: 2, c: 3, ..., z:26} I want to clone the object except for one element: {a: 1, c: 3, ..., z:26} What's the easiest way to do this (preferring to use es6/7 if possible)?
fox
  • 15,428
  • 20
  • 55
  • 85
196
votes
7 answers

How can I `await` on an Rx Observable?

I'd like to be able to await on an observable, e.g. const source = Rx.Observable.create(/* ... */) //... await source; A naive attempt results in the await resolving immediately and not blocking execution Edit: The pseudocode for my full intended…
CheapSteaks
  • 4,821
  • 3
  • 31
  • 48
176
votes
11 answers

Array.prototype.includes vs. Array.prototype.indexOf

Beyond the improved readability, is there any advantage to includes over indexOf? They seem identical to me. What is the difference between this var x = [1,2,3].indexOf(1) > -1; //true And this? var y = [1,2,3].includes(1); //true
Matt
  • 4,462
  • 5
  • 25
  • 35
175
votes
8 answers

Using `window.location.hash.includes` throws “Object doesn't support property or method 'includes'” in IE11

I am checking the URL to see if it contains or includes a ? in it to control the hash pop state in the window. All other browsers aren’t having an issue, only IE. The debugger gives me this error when I try to load in this way: Object doesn't…
Erik Grosskurth
  • 3,762
  • 5
  • 29
  • 44
122
votes
1 answer

Why is Math.pow() (sometimes) not equal to ** in JavaScript?

I've just discovered the ECMAScript 7 feature a**b as an alternative for Math.pow(a,b) (MDN Reference) and came across a discussion in that post, in which they apparently behave differently. I've tested it in Chrome 55 and can confirm that the…
Thomas Altmann
  • 1,744
  • 2
  • 11
  • 16
112
votes
6 answers

Can you use es6 import alias syntax for React Components?

I'm trying to do something like the following, however it returns null: import { Button as styledButton } from 'component-library' then attempting to render it as: import React, { PropTypes } from "react"; import cx from 'classNames'; import {…
Magnum
  • 2,299
  • 4
  • 17
  • 23
110
votes
3 answers

Succinct/concise syntax for 'optional' object keys in ES6/ES7?

There are already a lot of cool features in ES6/ES7 for defining Javascript objects. However, the following pattern is common in Javascript: const obj = { requiredKey1: ..., requiredKey2: ... }; if (someCondition) { obj.optionalKey1 =…
Andrew Mao
  • 35,740
  • 23
  • 143
  • 224
99
votes
6 answers

Best way to polyfill ES6 features in React app that uses create-react-app

I've been testing my React.js application on internet explorer, and finding that some ES6/7 code like Array.prototype.includes() breaks it. I'm using create-react-app, and apparently they've chosen not to include a lot of polyfills since not…
71
votes
2 answers

React with ES7: Uncaught TypeError: Cannot read property 'state' of undefined

I'm getting this error Uncaught TypeError: Cannot read property 'state' of undefined whenever I type anything in the input box of AuthorForm. I'm using React with ES7. The error occurs on 3rd line of setAuthorState function in ManageAuthorPage.…
Khpalwalk
  • 989
  • 1
  • 6
  • 11
66
votes
2 answers

ES7, ES8, ES9, ES10, ES11 Browser support

Regarding compatibility between ECMAScript specification and actual implementation; It is fairly easy to check out the data about browser support for ECMAScript2015 (ES6), but I found it pretty difficult to have an equivalently clear table for all…
Alvin Sartor
  • 2,249
  • 4
  • 20
  • 36
66
votes
6 answers

Find all matching elements with in an array of objects

I have an array of objects I am searching within the array like this let arr = [ { name:"string 1", arrayWithvalue:"1,2", other: "that" }, { name:"string 2", arrayWithvalue:"2", other: "that" }, { name:"string 2",…
ankur
  • 4,565
  • 14
  • 64
  • 100
62
votes
2 answers

ES2015/2016 way of 'typeof varName === 'undefined`?

I'm wallowing in ES2015+ luxury with a few projects right now and am wondering whether I can get rid of the much hated crutch to check for undefined in the new wonderland. Is there a shorter but still exact way to typeof varName === 'undefined' in…
Hedge
  • 16,142
  • 42
  • 141
  • 246
58
votes
2 answers

Why is -1**2 a syntax error in JavaScript?

Executing it in the browser console it says SyntaxError: Unexpected token **. Trying it in node: > -1**2 ... ... ... ...^C I thought this is an arithmetic expression where ** is the power operator. There is no such issue with other…
psmith
  • 2,292
  • 1
  • 19
  • 19
56
votes
8 answers

IE does not support Array includes or String includes methods

I have been working on a project and developing a JavaScript framework. The original code is about 700 lines so I only pasted this line. The includes method doesn't work on Internet Explorer. Is there any solution for this? var row_cells =…
50
votes
5 answers

How do I destructure all properties into the current scope/closure in ES2015?

I'd like to do something like this: const vegetableColors = {corn: 'yellow', peas: 'green'}; const {*} = vegetableColors; console.log(corn);// yellow console.log(peas);// green I can't seem to find or figure out how to do this but I really…
Resist Design
  • 4,462
  • 3
  • 22
  • 35
1
2 3
32 33