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
14
votes
2 answers

Trying ES6 imports with Chrome but it doesn't seem to work

I am contemplating moving from Dart to ES6 but Chrome doesn't seem to support the new import statement which is critical to me. I used the (named export) code from this site: http://www.2ality.com/2014/09/es6-modules-final.html I tried it even with …
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
14
votes
3 answers

What qualifies as being a dynamic export in ES6

I hear that dynamic exports/imports are not allowed in es6. This website Uses the example export default 5 * 7; as if it were a legal, static export. This seems reasonable since it clearly evaluates to the static value of 35, but I'm wondering what…
Kevin Wheeler
  • 1,331
  • 2
  • 15
  • 24
14
votes
1 answer

How does babel implement Set / Map polyfills

My question is related to computational complexity of Set / Map, Weak Set / Weak Map polyfills by Babel? Afaik there are no ES5 language features allowing to implement Set / Map directly, and so it might happen that Set / Map might use Array…
Lu4
  • 14,873
  • 15
  • 79
  • 132
14
votes
1 answer

Should the extension of built-in Javascript prototypes through symbols also be avoided?

It is the predominant opinion that built-in Javascript prototypes should not be extended (or altered in any way): Array.prototype.empty = function () { return this.length === 0; } // don't try that Does this rule also apply to ES2015 symbols? const…
user5536315
14
votes
2 answers

What's is the difference between Array.of(n) , Array(n) and array = [n]?

As the title, i'm wondering what's the difference between this 3 methods of initialization an array. I'm actually more interested in the new Array.of() method provided from ES6, why they feel the needs of implements that?
Stefano Saitta
  • 1,844
  • 1
  • 19
  • 34
14
votes
0 answers

SyntaxError: Unexpected token import

When I am running index.js its giving error SyntaxError: Unexpected token import. Though I am using babel to convert ES6 to ES5. package.json { "name": "espract", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { …
Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
14
votes
1 answer

Accessing ES6 super properties

So I was messing around with ES6 classes when I saw something surprising: class Animal { constructor(name) { this.name = name; } speak(sound) { console.log(sound); } } class Dog extends Animal { constructor(name,…
Downgoat
  • 13,771
  • 5
  • 46
  • 69
14
votes
3 answers

React TypeError this._test is not a function

Since im new to JavaScript and React, i really have problems figuring out the right syntax. Here my problem: _handleDrop(files) should call the function _validateXML(txt) but doesn't. I receive this error Uncaught TypeError: this._validateXML is…
Daniel Storch
  • 979
  • 3
  • 10
  • 25
14
votes
6 answers

Convert ES6 Class with Symbols to JSON

I have hardcoded classes to represent models in my Aurelia application. Here's a model 'PostEdit': var _postID = Symbol(); var _title = Symbol(); var _text = Symbol(); export class PostEdit { constructor(postEdit) { this[_postID] =…
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
14
votes
6 answers

Does JavaScript Promise.all have a callback that is fired when there are success AND failures

Am I misunderstanding Promise.all? I have X promises in an array and i'm trying to aggregate the success/failure ratio of the array. Here is what I think I know: Promise.all takes an array of promises. If all of the promises succeed then the .then…
Taysky
  • 4,331
  • 2
  • 20
  • 28
14
votes
1 answer

ES6 Classes implement indexer like arrays

I want to implement indexer to get elements from data property with index as JavaScript arrays. I heard about ES6 proxies but I couldn't implement it to my class. Is it possible now or should I wait more to come with ES7. class Polygon { …
moleschott
  • 161
  • 1
  • 4
14
votes
2 answers

ES6 reverse iterate an array using for..of, have I missed something in the spec?

In ES6 we now have iterators and for..of to iterate them. we have some built-ins for arrays; notably keys, values and entries. These methods allow one to perform much of the iteration one would commonly perform. But, what about iteration in reverse?…
Xotic750
  • 22,914
  • 8
  • 57
  • 79
14
votes
2 answers

Object.assign is not a function

I'm using babel with gulp and create a simple DOM library in ES6. But after running and when i'm going to use it, I got the Object.assign is not a function in chrome console. this is the gulp code gulp.task('scripts', function() { return…
TIJ
  • 2,771
  • 3
  • 19
  • 32
14
votes
2 answers

Extended Errors do not have message or stack trace

When running this snippet through BabelJS: class FooError extends Error { constructor(message) { super(message); } } let error = new FooError('foo'); console.log(error, error.message, error.stack); it outputs {} which is not what I…
ssube
  • 47,010
  • 7
  • 103
  • 140
14
votes
1 answer

ES6 classes : what about instrospection?

In ES5, I could check the existence of a "class" (constructor function) on the window object: if (window.MyClass) { ... // do something } In ES6, according to this article, globally-declared classes are globals, but not properties of the global…
Samuel Maisonneuve
  • 1,025
  • 10
  • 21