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

Count Array Items in Object of Arrays (combined count)

Consider the following object: const test = { foo: ['foo', 'bar', 'foobar'], bar: ['foo', 'bar', 'foobar'] foobar: ['foo', 'bar', 'foobar'] }; How would one go about getting the combined count of all of the items within each of the…
Ben Carey
  • 16,540
  • 19
  • 87
  • 169
3
votes
1 answer

Is the following a proper way to write long computations in JavaScript that needs to run on a browser?

I am trying to use async / await to do long computations on JavaScript on a browser. Should the code be changed or any improvements be done? It seems using promises may make it complicated. I also have two related questions at the end of the…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
3
votes
2 answers

How to get Javascript's IMPORT EXPORT working. Do I need transpiler?

I am so confused about this. All I want to do is simply break up my javascript into modules, and include them in certain pages. Some pages may need my user-module.js , some pages may not. I have Googled, read the tutorials, and it's still not…
John S.
  • 504
  • 1
  • 3
  • 18
3
votes
2 answers

javascript await on multiple chained async functions

Say I have the following: const a = new A(); await a.getB().action(); A.prototype.getB() is async as-well as B.prototype.action(). If I try to await on the chaining of the functions I get an error: TypeError: a.getB(...).action is not a…
Jorayen
  • 1,737
  • 2
  • 21
  • 52
3
votes
2 answers

Issue with try catch in async await

I am struggling with async await try catch block for a couple of days. async function executeJob(job) { // necessary variable declaration code here try { do { let procedureRequests = await ProcedureRequestModel.find(filter,…
Vishnu
  • 704
  • 12
  • 34
3
votes
2 answers

Why does javascript let you add comma in the end of function parameters?

I have encountered a change in the javascript function declaration that seems to be off. You can make a function like this: let a = function (b,) { console.log(b); } I have found that the trailing comma in function parameters is allowed because…
3
votes
2 answers

Avoid bringing code from imports of imports

I'm going through the exercise of making my webpack bundle smaller, and using webpack's bundle analyzer I saw that a really heavy package is being included in two different async chunks, even though it's only used once. After some digging in my…
3
votes
2 answers

How to return value from async/await function?

Using puppeteer to collect data from 2 different webpages into arrays for later comparison. However the program does not wait for the returned array before carrying forward. async function go(){ try{ const browser = await puppeteer.launch(); …
3
votes
1 answer

Can I "promisify" a function by just using async?

So I have a function that should immediatly return a rejected or resolved Promise, i.e. it is basically a snychronous function I want to "promisify". What I usually do in such cases is something like this: func() { // some code to check for an…
frontend_dev
  • 1,693
  • 14
  • 28
3
votes
1 answer

Mocha not showing chai expect error messages

I'm using Mocha and Chai + ChaiHttp for testing my API. The problem I have is that I don't see any error messages when a expect statement is failing. Here is my code: it('POST /signup : should create a new user', async () => { const user = { …
Felix
  • 166
  • 1
  • 4
  • 20
3
votes
0 answers

How to generate es2017 code with webpack?

I am currently migrating an old Firefox extension and want to use the es2017 features. The dependencies: "devDependencies": { "babel-core": "^6.26.0", "babel-loader": "^7.1.4", "babel-preset-env": "^1.6.1", "babel-preset-es2017": "^6.24.1", …
Nabor
  • 1,661
  • 3
  • 20
  • 45
3
votes
3 answers

JavaScript/Angular 1 - Promise.all to async-await

I assign two calls to the web service in two variables in referencesPromise and contactTypesPromise $onInit() (I can create a new method for that, if needed) $onInit() { const referencesPromise =…
Mouad Ennaciri
  • 1,217
  • 3
  • 15
  • 28
3
votes
3 answers

Await for asynchronous function results in undefined

I'm having trouble with async/await with Node. When I try this: function Read_Json_File() { fs.readFile('import.json','utf-8',(err, data) => { if (err) throw err; json_data = JSON.parse(data); return json_data; …
user8675491
3
votes
0 answers

Migrating from generators to async / await

I am having an issue migrating below two functions from generators to async / await. When I await the endPoints inside send(), I get the promise return value from fixedPublisher() as undefined. Am I missing anything below ? Generators: export…
3
votes
1 answer

unexpected token import in ES2017 with babel and Jest

I try to use Jest with bablejs and ES2017 in my project, according to the Jest Getting Started page and also Bablejs config for ES2017 this is my .babelrc file : { "presets": ["es2017"], "env": { "test": { "presets": ["es2017"] } …
MBehtemam
  • 7,865
  • 15
  • 66
  • 108