ecmascript-next

Node.js assert.throws with async functions (Promises)

旧城冷巷雨未停 提交于 2019-12-09 05:09:36
问题 I want to check if an async function throws using assert.throws from the native assert module. I tried with const test = async () => await aPromise(); assert.throws(test); // AssertionError: Missing expected exception.. It (obvioulsy?) doesn't work because the function exits before the Promise is resolved. Yet I found this question where the same things is attained using callbacks. Any suggestion? (I'm transpiling to Node.js native generators using Babel) 回答1: node 10 and newer Since Node.js

Why So Many IANA Time Zones Names?

醉酒当歌 提交于 2019-12-07 07:08:28
问题 Javascript allows you to see what time it is in another timezone if you specify the IANA given name of that timezone. For example: new Date().toLocaleString("en-US", {timeZone: "America/Chicago"}); Below you can see that IANA provides multiple names within each general timezone: America/New_York Eastern (most areas) America/Detroit Eastern - MI (most areas) America/Kentucky/Louisville Eastern - KY (Louisville area) America/Kentucky/Monticello Eastern - KY (Wayne) America/Indiana/Indianapolis

Why was await* removed from the async/await proposal?

穿精又带淫゛_ 提交于 2019-12-07 01:42:15
问题 The only place it seems to be documented is this issue thread and the actual specification. However, the reasoning for the removal isn't posted anywhere I could find. The new recommended way seems to be await Promise.all() , but I'm curious as to why await* was removed. 回答1: Well, the last revision of the readme before it was removed already mentions everything in that paragraph: await* and parallelism In generators, both yield and yield* can be used. In async functions, only await is allowed

JavaScript async/await for Promises inside Array.map() [duplicate]

旧时模样 提交于 2019-12-06 11:45:26
问题 This question already has answers here : Using async/await with a forEach loop (17 answers) Closed 3 years ago . Given the following code class SomeClass { async someFunc() { const urlParameters = [0, 1, 2]; const batchAjaxResult = await urlParameters.map((parameter) => { const result = await $.get(`someUrl/${parameter}`); return { parameter, result } }); console.log(batchAjaxResult); } } JavaScript will return an Array of resolved Promises instead of the actual Promises result. This is

How do I get decorators working with babel & webpack?

时光毁灭记忆、已成空白 提交于 2019-12-06 04:24:32
问题 I have the following setup: { "babel-core": "~5.8.25", "babel-eslint": "^4.1.3", "babel-loader": "~5.3.2", "babel-polyfill": "^6.2.0", "eslint": "^1.7.3", "eslint-config-airbnb": "^0.1.0", "eslint-loader": "~1.1.0", "eslint-plugin-angular": "~0.12.0", // ... } webpack: module: { preLoaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'eslint-loader'}], loaders: [ { test: /\.js$/, exclude: /node_modules/, loaders: ['ng-annotate', 'babel-loader?plugins[]=transform-decorators-legacy'], }

Using ES7 static propTypes with React-Native

我的梦境 提交于 2019-12-06 00:44:08
问题 When I'm launching my project using React-Native default packager, I have this error: Unexpected token on this line: static propTypes = { /// ... }; I took a look on React-Native issues on GitHub, but I didn't find a solution. Any suggestion? 回答1: React-Native packager use Babel for transfer ES6 and ES7, but NOT ALL features. The enable list is here. In your case, class-props is not enabled by default in RN packager. You can use Babel to compiler your code before packager, or just enable it

Dependency injection library - renaming injected values

痞子三分冷 提交于 2019-12-05 23:51:56
问题 I'd like to inject lodash by name, something like this: let val = function(lodash){ // lodash will be injected, simply by using require('lodash'); }; but say I want to rename the import, I want do something like this: let val = function({lodash:_}){ }; or let val = function(lodash as _){ }; is there a way to do this with either ES6/ES7/ES8 or TypeScript? Note that this DI framework does more work than just require('x')...it will try to inject other values first, if nothing else exists, then

Why So Many IANA Time Zones Names?

醉酒当歌 提交于 2019-12-05 12:44:50
Javascript allows you to see what time it is in another timezone if you specify the IANA given name of that timezone. For example: new Date().toLocaleString("en-US", {timeZone: "America/Chicago"}); Below you can see that IANA provides multiple names within each general timezone: America/New_York Eastern (most areas) America/Detroit Eastern - MI (most areas) America/Kentucky/Louisville Eastern - KY (Louisville area) America/Kentucky/Monticello Eastern - KY (Wayne) America/Indiana/Indianapolis Eastern - IN (most areas) America/Indiana/Vincennes Eastern - IN (Da, Du, K, Mn) America/Indiana

Destructure array to object property keys

北城余情 提交于 2019-12-05 10:40:22
问题 I have an array of values like: const arr = [1,2,3]; Is there any way I can use destructuring to create the following output? If not, what is the easiest way I can do this in ES6 (or later)? const obj = { one: 1, two: 2, three: 3 }; I tried this, but I guess it doesn't work as this is the syntax for computed keys: const arr = [1,2,3]; const obj = { [one, two, three] = arr }; 回答1: I don't believe there's any structuring/destructuring solution to doing that in a single step, no. I wanted

Async/Await not waiting

谁说胖子不能爱 提交于 2019-12-05 03:41:29
I'm running into an issue which I don't fully understand. I feel like there are likely concepts which I haven't grasped, code that could be optimized, and possibly a bug thrown in for good measure. To greatly simplify the overall flow: A request is made to an external API The returned JSON object is parsed and scanned for link references If any link references are found, additional requests are made to populate/replace link references with real JSON data Once all link references have been replaced, the original request is returned and used to build content Here, is the original request (#1):