Questions tagged [ecmascript-2018]

ECMAScript 2018 (ES2018) is the 9th version of the ECMAScript language. Main features include asynchronous iteration, rest/spread properties and various extensions to regular expressions. Only use this tag where the question specifically relates to new features or technical changes provided in ECMAScript 2018.

ECMAScript 2018 (ES2018) is the 9th version of the language.

The following features have been introduced

Links

38 questions
21
votes
3 answers

JavaScript - spread and rest syntax to remove specific property from object

I have an object as follows : let obj = {foo: 1, bar: 2, baz: 3} I would like to delete a specific property by calling a method that takes as parameter the name of the property to delete removeProperty(obj, propertyName) { let { propertyName, _,…
Mouad Ennaciri
  • 1,217
  • 3
  • 15
  • 28
10
votes
1 answer

Asking for examples of async generators not directly transformable into manually implemented async iteration

Async generators use an internal queue to handle synchronous next, thrown, and return methods calls. I was trying to construct a situation where this queue is mandatory for the success of the iteration itself. Therefore, I'm looking for some cases…
8
votes
2 answers

Applying spread operator on object with getter

If you declare a class with a getter class Person { constructor(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } get fullName() { return [this.firstName, this.lastName].join(" "); } } you can…
BassT
  • 819
  • 7
  • 22
8
votes
2 answers

ES6 Spread operator to vanilla Javascript

I have added a script that uses ES6 spread operator to the project that gets the params from the url. Unsure how to revert this to the normal vanilla Javascript syntax after I discovered that the project doesn't support ES6. It's easy to take normal…
Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37
7
votes
3 answers

Prevent all or some DOM content to be parsed, per website domain

I have created a small imperative vanilla JavaScript script to block distracting news websites I feel an addiction-like behavior to: // ==UserScript== // @name blocksite // @match *://*.news_site_1.com/* // @match …
user11744452
7
votes
3 answers

Using javascript's Symbol.asyncIterator with for await of loop

I am trying to understand javascript's Symbol.asyncIterator and for await of. I wrote some simple code and it throws an error saying: TypeError: undefined is not a function on the line which tries to use for await (let x of a). I could not…
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
5
votes
1 answer

Does the Object spread syntax never throw an error?

I noticed that the Object Spread syntax is extremely permissive on what kinds of values it can accept: console.log({ ...true }); console.log({ ...false }); console.log({ ...0 }); console.log({ ...42 }); console.log({ ...-1 }); console.log({…
Phil Kang
  • 920
  • 8
  • 18
4
votes
1 answer

Can not use 'yield' as identifier inside a generator

While composing an async generator function, I noticed that the following construct results in a SyntaxError: async function * foo() { await yield bar; // Can not use 'yield' as identifier inside a generator } Even though reversing the order of…
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
4
votes
2 answers

How to use special characters (like hyphen) in destructuring assignment syntax?

I'm curious of why that seems impossible: const {a, b, 'special-one'} = { a:1, b:2, 'special-one': 3 }; // output => missing : after property id Will it be possible to find that syntax working in future ES versions ? Thanks for your lights :)
TOPKAT
  • 6,667
  • 2
  • 44
  • 72
4
votes
1 answer

Array Argument not Extensible in Tag Function

Typically, arrays in javascript are extensible, but this is not true for the array passed as the first argument of a tag function: let ary = [1,2,3]; console.log(Object.isExtensible(ary)); // returns true function tag(ary,…
Lonnie Best
  • 9,936
  • 10
  • 57
  • 97
4
votes
2 answers

inlining spread operator during declaration es2018

I want to do something like this: const translations = { en: { statistics_title: 'Statistics' }, ru: { statistics_title: 'Статистика' }, uk: { ...ru } } obviously it doesn't work, of course, I can…
Maksym D.
  • 61
  • 4
3
votes
3 answers

replace variable names with string.replace(regex, value)

Trying to do what I thought was a fairly simple string replacement, but turns out to be more complicated than I thought. If I have a string like months + 3 + (startmonths * 3) + months - (months*7) + (monthsend*5) For clarity, the "formula" I am…
GGizmos
  • 3,443
  • 4
  • 27
  • 72
3
votes
3 answers

Spread syntax for complex objects

Assume I have an object like this let store = { "articles": [{...}, {...}, ...], "errors": { "p1": { "myNewObject":0 }, "p2": {...}, ...} } I want to take advantage of Spread syntax to return a clone of this object where store.errors.p1 is a…
Naigel
  • 9,086
  • 16
  • 65
  • 106
3
votes
0 answers

Test Browser Compatibility for New Regular Expression Features

What's the best practice for determining if a browser supports the new regular expression features specified in the ECMAScript 2018 Language Specification? I suspect you just have to write try catch statements or do it by detecting browser…
Lonnie Best
  • 9,936
  • 10
  • 57
  • 97
3
votes
1 answer

Custom Elements - Naming Collisions Extending HTMLElement

Custom Elements are created by extending the HTMLElement class. Therefore, when you create one, is seems you'd have to take special precautions not to give your Custom Element any custom-property-names that are already inherited from HTMLElement. I…
1
2 3