ecmascript-2017

ES7, ES8, ES9, ES10 Browser support [closed]

走远了吗. 提交于 2021-01-18 05:59:12
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 months ago . Improve this question It is fairly easy to check out the data about browser support for ECMAScript2015 (ES6), but I found it pretty difficult to have an equivalently clear table for all the following ES versions (ES7 to ES10). Mozilla has some info on their website, it is possible to

Node repl with async await

不羁岁月 提交于 2020-12-29 02:42:46
问题 I would like to add support to async/await to node repl Following this issue: https://github.com/nodejs/node/issues/8382 I've tried to use this one https://github.com/paulserraino/babel-repl but it is missing async await suppport I would like to use this snippet const awaitMatcher = /^(?:\s*(?:(?:let|var|const)\s)?\s*([^=]+)=\s*|^\s*)(await\s[\s\S]*)/; const asyncWrapper = (code, binder) => { let assign = binder ? `root.${binder} = ` : ''; return `(function(){ async function _wrap() { return

ECMAScript object spread/rest - assigning to multiple properties at once

你离开我真会死。 提交于 2020-07-15 09:29:28
问题 The new object rest/spread syntax has some surprisingly nice applications, like omitting a field from an object. Is there a (proposed) way to also assign to several properties of an object, the values from variables with the same names? In other words, a shorter way to say: o.foo = foo; o.bar = bar; o.baz = baz; Note: Without losing the existing properties of o , only adding to them. 回答1: Use Object.assign : const o = { initial: 'initial' }; const foo = 'foo'; const bar = 'bar'; const baz =

ECMAScript object spread/rest - assigning to multiple properties at once

孤人 提交于 2020-07-15 09:26:17
问题 The new object rest/spread syntax has some surprisingly nice applications, like omitting a field from an object. Is there a (proposed) way to also assign to several properties of an object, the values from variables with the same names? In other words, a shorter way to say: o.foo = foo; o.bar = bar; o.baz = baz; Note: Without losing the existing properties of o , only adding to them. 回答1: Use Object.assign : const o = { initial: 'initial' }; const foo = 'foo'; const bar = 'bar'; const baz =

javascript await on multiple chained async functions

心不动则不痛 提交于 2020-05-31 05:45:11
问题 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 function . If I am separating the chaining of the functions and awaiting each promise it works fine. Is there a way to chain these promises and await them together? 回答1: This is because getB is an async function and does not return a B object but a Promise

react-native async function returns promise but not my json data?

妖精的绣舞 提交于 2020-05-24 18:15:47
问题 I'm learning react-native, and I'm running into an issue. Why does getting data on return from an async function return a promise, but in the async function itself, it correctly returns an array of objects? On componentDidMount() , I call my async function which in turn does a fetch to an api url: componentDidMount() { let data = this.getData(); console.log(data); // <-- Promise {_40: 0, _65: 0, _55: null, _72: null} this.setState({ dataSource:this.state.dataSource.cloneWithRows(data), }) }

async function with the class in javascript

烈酒焚心 提交于 2020-04-10 09:20:47
问题 I have create a class in nodejs class ApnService { sendNotification(deviceType, deviceToken, msg, type, id) { try { const note = await apnProvider.send(note, deviceToken) console.log(note) } catch (err) { console.log(err) } } } export default ApnService What I need to do is to convert above function to async . But when I use below syntax It throws me error SyntaxError: src/services/apn.js: Unexpected token (43:19) 41 | } 42 | > 43 | sendNotification = async(deviceType, deviceToken, msg, type,

karma-typescript: import JS file with Async keyword

不羁岁月 提交于 2020-01-14 07:48:11
问题 I'm using karma-typescript, with this karma config file : karmaTypescriptConfig: { compilerOptions: { target: "es5", lib: ["dom", "es2015", "es2017"] }, bundlerOptions: { transforms: [require("karma-typescript-es6-transform")()] } }, In my spec files, I have this code : import {} from './local/lib.js' In my lib.js, I have this code : async function() {} When executing my tests with npm test , I have this error : ERROR [source-reader.karma-typescript] Error parsing code: Unexpected token (X:Y)

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

ぃ、小莉子 提交于 2020-01-11 09:29:39
问题 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 I'm curious is that, for example, Map defines an interface with several iterators (entries, values, keys) and it seems that if not specified explicitly the for..of loop uses the iterator returned by map.entries() call. I've trying searching in the

Is it possible to resolve async function without return keyword

杀马特。学长 韩版系。学妹 提交于 2020-01-10 18:41:18
问题 I started to use ES7 feature async/await , which gives the best approach to deal with asynchronous tasks, and makes your code cleaner and readable. However it doesn't give you an access to Promise, created by async function, so if you do some async request in your async function you should promisify it, then await it and then return the result. I mean this: async function doStuff() { //stuff... var value = await new Promise(function(resolve) { $.get('http://some/url/...', function(result) { /