Questions tagged [ecmascript-6]

The 2015 version of the ECMAScript specification, now a standard (ECMAScript 2015). Only use this tag where the question specifically relates to new features or technical changes provided in ECMAScript 2015.

ECMAScript 2015 (also known as ECMAScript 6) is the 2015 specification for the language (now superseded by the yearly released versions, managed by TC39). ES2015 adds significant updates to the language and its implementation in major JavaScript engines is almost complete (except legacy browsers, like Internet Explorer).

The tag or its alias should be used when your question covers one of the ES2015/ES6 features.

Related, transpiler specific tags are: ,


Features

  • Arrow functions
  • Classes
  • Enhanced Object Literals
  • Template Strings
  • Destructuring
  • Default + Rest + Spread
  • let + const
  • Iterators + for..of
  • Generators
  • Unicode
  • Modules
  • Module Loaders
  • Map + Set + Weakmap + Weakset
  • Proxies
  • Symbols
  • Subclassable Built-ins
  • Promises
  • Math + Number + String + Array + Object APIs
  • Binary and Octal Literals
  • Reflect API
  • Tail Calls
  • Typed arrays and DataViews

Useful Links

29895 questions
13
votes
2 answers

SpyOn individually exported ES6 functions

tl;dr: I use Jasmine; I want to test aaa function which called bbb from the same module; I want to spy on bbb, but eventually aaa called the original bbb function, not a spy; How can I force aaa to call the spy? The Module: export function…
S Panfilov
  • 16,641
  • 17
  • 74
  • 96
13
votes
3 answers

Calling a method of a super-super class

I'm having trouble accessing a method in a hierarchy when each class contains a method with the same name. class A { constructor(private name: string) { } notify() { alert(this.name) } } class B extends A { constructor() { …
Milo711
  • 265
  • 1
  • 3
  • 9
13
votes
1 answer

Difference between mobx's `action.bound` and arrow functions on class functions?

Using arrow functions on a class with babel transpiles it so the definition is bound in the constructor. And so it is not in the prototype and it is not available via super when inheriting. It is also not as efficient when scaling by creating many…
bitten
  • 2,463
  • 2
  • 25
  • 44
13
votes
4 answers

check if two arrays contain identical objects - react componentDidUpdate

I am using React's componentDidUpdate lifecycle method. I am trying to determine whether or not two arrays are the same. My prevState array looks like this: prevState.players = [ { name: 'Wayne Rooney', age: 31 }, { name: 'Lionel…
peter flanagan
  • 9,195
  • 26
  • 73
  • 127
13
votes
3 answers

FP alternative to polymorphism in JavaScript/ReactJS

I'm currently working on a ReactJS project where I need to create "re-usable" components in which some of the methods would need to be "overridden". In OOP I would use polymorphism. I've done some reading and it seems the consensus is to use…
Wancieho
  • 708
  • 1
  • 7
  • 25
13
votes
6 answers

Update nested object using Object.assign

I have the following object. This object gets assigned a new value when the user clicks on a button. state = { title: '', id: '', imageId: '', boarding: { id: '', test: '', work: { title: '', id: '' } } } My…
fscore
  • 2,567
  • 7
  • 40
  • 74
13
votes
1 answer

ES6 async/await in classes

I'm trying to create a class that will send a post request (login), save the cookie and use that cookie for other operations such as download a file. I created a local server that that will receive a post http method with user and password in it and…
vajehu
  • 181
  • 1
  • 2
  • 10
13
votes
3 answers

How to catch an exception inside an event listener?

I use Puppeteer library to open an URL and process all requests' responses. Sometimes inside the event listener page.on('response') I need to throw an error like in the example below. But I'm unable to catch these exceptions in any way, I always got…
pronngo
  • 820
  • 11
  • 26
13
votes
2 answers

Execution time with process.hrtime() return vastly different result

I'm having trouble explaining why my performance test return significantly different results on 2 different types of run. Steps to reproduce issue: Get the code from gist: https://gist.github.com/AVAVT/83685bfe5280efc7278465f90657b9ea Run node…
AVAVT
  • 7,058
  • 2
  • 21
  • 44
13
votes
3 answers

Destructuring assignment in function call while preserving the object

Is there a way to do something like the following? f = (o:{a:x}) { console.log(o); console.log(x); } f({a:0}); //Should Print: //{a:0} //0 To get the same result as the this. f = function(o) { var {a:x} = o; console.log(o); …
Diasiare
  • 745
  • 1
  • 6
  • 18
13
votes
1 answer

opening a modal with the click of a button

The next code uses a Modal react component: export class AddWorkLogEditor extends React.Component { constructor(props) { super(props); this.addWorkLog = this.addWorkLog.bind(this); this.onOpenModal =…
Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56
13
votes
2 answers

Is there a BNF grammar openly available for JavaScript ES6?

I am working on a merge tool for JavaScript programs, and I need to write a grammar for JavaScript (version >= ES6) in JavaCC format. For that, I want to use an openly available BNF grammar for ES6, then I would write the grammar in JavaCC format…
13
votes
3 answers

Is the constructor still needed in React with autobinding and property initializers

I am refactoring an es6 class based React component that uses the normal constructor, and then binds methods, and defines state/attributes within that constructor. Something like this: class MySpecialComponent extends React.Component { …
Max Millington
  • 4,378
  • 4
  • 27
  • 34
13
votes
2 answers

Space after symbol with JS Intl

I want to format a currency with NumberFormat of Intl and get the returned value with a space " " between the symbol and the number. new Intl.NumberFormat('pt-br', { style: 'currency', currency: 'USD' }).format(12345) // "US$12.345,00" new…
13
votes
2 answers

why do functional component in reactjs not have instances?

In React quickstart, it is stated about Refs and Functional Components that You may not use the ref attribute on functional components because they don't have instances: function MyFunctionalComponent() { return ; } class Parent…
thor
  • 21,418
  • 31
  • 87
  • 173