Questions tagged [ecmascript-2017]

Use this tag for questions about features finalized in ECMAScript 2017. Do *not* use this tag if the code in question merely *uses* one of the features, *unless* the feature is cause of the problem.

Proposals finalized in 2017 include:

387 questions
4
votes
4 answers

How can I remove an event listener no matter how the callback is defined

For years I ran into problems trying to remove an event listener in JavaScript. Often I would have to create an independent function as the handler. But that is just sloppy and, especially with the addition of arrow functions, just a pain. I am not…
Intervalia
  • 10,248
  • 2
  • 30
  • 60
4
votes
2 answers

how to reuse es6 class in vue js?

How to reuse some existing ES6 classes in Vue Js. Have a class which has a variable being updated by observable. class A { public a: string; someobservable.subscribe((a) =>{ this.a = a; }) } In vue.JS have created the object…
4
votes
1 answer

JavaScript async/await not awaiting properly?

I'm having an issue with JavaScript's async/await functions. This is happening on an internal application that I can't share the source for, but I put together a quick generic reproduction of my issue: function sleep(ms) { return new…
CaptObvious
  • 83
  • 1
  • 1
  • 7
4
votes
1 answer

javascript: async / await – propagation required the entire call chain up?

I am wrapping a function returning a promises into an async function on a small helper function... trash(filesArray, { glob: false }) .then(() => { resolve(true); }).catch((err) => { return err; }) …because I like to use it synchronous…
Frank N
  • 9,625
  • 4
  • 80
  • 110
4
votes
3 answers

Convert async await in while loop to promises

I can't figure out how to convert async await functionality in a while loop to a promise based implementation. repl showing the async await version https://repl.it/repls/IdealisticPepperyCoding var dependency = false; function checkDependency()…
Zack Lucky
  • 671
  • 3
  • 10
  • 25
4
votes
1 answer

Calling super class' async method from async method in extending class

I'm writing JavaScript (> ECMAScript 6) and I can't figure how to call a super class' async method in an extending class' method. This is what I'm trying to do: class SuperClass { constructor(){} async method() { return; …
4
votes
1 answer

Using Promises with Await/Async Correctly

I'm having some issues understanding how the Promise functionality works, I have previously used Bluebird but I wanted to try to learn the new await/async standard in order to improve as a programmer. I have used async/await and created promises…
Crafty
  • 41
  • 2
4
votes
2 answers

Converting await in infinite for loop into raw promise.then

As far as I know, async/await is just syntactic sugar over promise.then. Consider this code snippet: function sleep(n){ return new Promise(res => setTimeout(res, n)); } function* range(n){ var i = 0; while(i < n) yield i++; } async…
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
4
votes
1 answer

how to properly use the async and await keywords within a map

I have the following snippet of code export const fetchPosts = () => async dispatch => { const res = await axios.get(`${url}/posts`, { headers: { ...headers } }); console.log(res.data); let posts = res.data.map(p => (p.comments =…
4
votes
2 answers

How does `for..of` loop resolve the iterator from an object?

For an object to implement iterable interface it must implement [Symbol.iterator] key that points to a function that returns the iterator. I'm wondering if the for..of loop internally calls this method on an object to get that iterator? The reason…
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
4
votes
0 answers

Implement PassportJS (local-strategy) custom callback using async/await

I've implemented passport local strategy using async/await as below const strategy = new LocalStrategy( async(username, password, done) => { try { // Find the user given the username const user = await User.findOne({ username }); …
4
votes
2 answers

ES8 using arrow function with async and await

I'm currently learning how to use ES8's fetch, async and await I currently have this code that works: const url = "https://api.icndb.com/jokes/random"; async function tellJoke() { let data = await (await fetch(url)).json(); return…
4
votes
3 answers

How do you create a named async arrow function?

Currently, I have this code: async function getConnection(){ // logic here... } To make it consistent with the rest of my codebase, I want to change it to an arrow function. I've tried async getConnection () => { ... } but that didn't seem to…
ifvictr
  • 141
  • 2
  • 3
  • 13
4
votes
2 answers

Why does .catch() not catch reject() within Promise constructor within loop at an async function unless Error is passed?

Given (async () => { const p = await new Promise((resolve, reject) => setTimeout(() => { reject(new Error(1)) }, Math.floor(Math.random() * 1000))); return p})() .then(data => console.log(data)) .catch(err =>…
guest271314
  • 1
  • 15
  • 104
  • 177
4
votes
1 answer

jQuery proxy doesn't call async functions

I've found that I can't call async functions with $.proxy. My case was that I proxied event listeners so that they'd still have the same context, but as soon as I tried proxying to an async function, it just didn't get called - also, no errors were…
macbem
  • 1,180
  • 2
  • 9
  • 21