Clean way to keep original variable and destructure at the same time
One possible way: const result = doSomething(), { a, b } = result; You still have to duplicate the name, though. const token isn’t quite right-handy. )
One possible way: const result = doSomething(), { a, b } = result; You still have to duplicate the name, though. const token isn’t quite right-handy. )
As mentioned in the issue you filed, the core issue is that await* is no longer a thing and has been removed. Unfortunately, it was not properly throwing a syntax error in Babel 6 and was essentially being treated like a normal await. You’ll need to explicitly let [p1, p2] = await Promise.all([ System.import(‘./package1.js’), System.import(‘./package2.js’)]);
Yes, you can do that, and it will run the two asynchronous functions in parallel. You’ve just created a promise and thrown it away. However, this means that when the promise is rejected you won’t notice. You’ll just get an unhandledRejection eventually which will crash your process if not handled. Is this OK? How can … Read more
You can assign destructured values not only to variables but also to existing objects: const arr = [1,2,3], o = {}; ({0:o.one, 1:o.two, 2:o.three} = arr); This works without any additional variables and is less repetitive. However, it also requires two steps, if you are very particular about it.
An easy function to use and understand for some async replace : async function replaceAsync(str, regex, asyncFn) { const promises = []; str.replace(regex, (match, …args) => { const promise = asyncFn(match, …args); promises.push(promise); }); const data = await Promise.all(promises); return str.replace(regex, () => data.shift()); } It does the replace function twice so watch out if … Read more
Dealing with unhandled rejected native promises (and async/await uses native promises) is a feature supported now in V8. It’s used in the latest Chrome to output debugging information when a rejected promise is unhandled; try the following at the Babel REPL: async function executor() { console.log(“execute”); } async function doStuff() { console.log(“do stuff”); throw new … Read more
How I proceed: install globally eslint : npm install -g eslint install babel-eslint : npm install –save-dev babel-eslint install eslint-plugin-react : npm install –save-dev eslint-plugin-react create .eslintrc file in you root directory. here is my config: { “env”: { “browser”: true, “node”: true, “es6”: true, “jest”: true, “jquery”: true }, “parser”: “babel-eslint”, “parserOptions”: { “ecmaVersion”: … Read more
None. As you can read in the ES7 spec, both Math.pow and the ** exponentation operator cast their arguments/operands to numbers and use the very same algorithm to determine the result. Addendum: this changed with the introduction of the BigInt type in ES2020, whose values are only supported by operators (including **) but not the … Read more
There is a more simpler solution you can try. const mapObject = new Map(); mapObject.set(1, ‘hello’); console.log([…mapObject.entries()]); // [[1, “hello”]] console.log([…mapObject.keys()]); // [1] console.log([…mapObject.values()]); // [“hello”]
You have to bind your event handlers to correct context (this): onChange={this.setAuthorState.bind(this)}