ecmascript-next

Why do javascript functions need to have the keyword “async”? Isn't the “await” keyword enough? [closed]

て烟熏妆下的殇ゞ 提交于 2021-02-20 10:25:16
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . Improve this question For instance, why does the function below need to have "async".. isn't using await specific enough for the compiler to parse the code without ambiguity? # Why do we need async here async function foo() { var user = await getUser(user_id); console.log

Why do javascript functions need to have the keyword “async”? Isn't the “await” keyword enough? [closed]

夙愿已清 提交于 2021-02-20 10:19:19
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . Improve this question For instance, why does the function below need to have "async".. isn't using await specific enough for the compiler to parse the code without ambiguity? # Why do we need async here async function foo() { var user = await getUser(user_id); console.log

Why do I have to put async keyword to functions which have await keywords?

浪尽此生 提交于 2021-02-18 22:33:06
问题 I just want to wait for a process to finish, not want to make the function asynchronous. See the below code. I had to make getUserList asynchronous because there was an await keyword in the function. Therefore I also had to write like "await UsersService.getUserList" to execute the method and also I had to make the parent function asynchronous. That's not what I want to do. import xr from 'xr' //a package for http requests class UsersService { static async getUserList() { const res = await xr

Why do I have to put async keyword to functions which have await keywords?

风流意气都作罢 提交于 2021-02-18 22:30:27
问题 I just want to wait for a process to finish, not want to make the function asynchronous. See the below code. I had to make getUserList asynchronous because there was an await keyword in the function. Therefore I also had to write like "await UsersService.getUserList" to execute the method and also I had to make the parent function asynchronous. That's not what I want to do. import xr from 'xr' //a package for http requests class UsersService { static async getUserList() { const res = await xr

ECMAScript proposal for constructor parameter properties

落花浮王杯 提交于 2021-02-15 07:02:30
问题 In TypeScript, there is convenient syntax, constructor parameter properties: constructor(a, public b, private _c) {} Which is syntactic sugar for: constructor(a, b, _c) { this.b = b; this._c = _c; } Considering that there are ECMAScript proposals for other features that previously were specific to TypeScript like class fields and their visibility, it would be reasonable to get parameter properties, too. Are there proposals or other initiatives for constructor parameter properties in

ECMAScript proposal for constructor parameter properties

泪湿孤枕 提交于 2021-02-15 07:01:25
问题 In TypeScript, there is convenient syntax, constructor parameter properties: constructor(a, public b, private _c) {} Which is syntactic sugar for: constructor(a, b, _c) { this.b = b; this._c = _c; } Considering that there are ECMAScript proposals for other features that previously were specific to TypeScript like class fields and their visibility, it would be reasonable to get parameter properties, too. Are there proposals or other initiatives for constructor parameter properties in

Why BigInt demand explicit conversion from Number?

扶醉桌前 提交于 2021-02-10 07:54:23
问题 BigInt and Number conversions When working with numbers in JavaScript there are two primitive types to choose from - BigInt and Number. One could expect implicit conversion from " smaller " type to " bigger " type which isn't a case in JavaScript. Expected When computing some combination of BigInt and Number user could expect implicit cast from Number to BigInt like in below example: const number = 16n + 32; // DOESN'T WORK // Expected: Evaluates to 48n Actual behavior Expressions operating

Wrapping promise in async/await

家住魔仙堡 提交于 2021-02-07 03:22:22
问题 I'm struggling a bit with async/await and returning a value from a Promise. function test () { return new Promise((resolve, reject) => { resolve('Hello') }) } async function c() { await test() } As I understood things I should be able to get a value by doing: console.log(c()) But clearly I am missing a point here as this returns a promise. Shouldn't it print "hello"? On a similar note I am unclear as to whether a callback needs to be converted to a promise before wrapping it in async/await?

Wrapping promise in async/await

ぐ巨炮叔叔 提交于 2021-02-07 03:22:02
问题 I'm struggling a bit with async/await and returning a value from a Promise. function test () { return new Promise((resolve, reject) => { resolve('Hello') }) } async function c() { await test() } As I understood things I should be able to get a value by doing: console.log(c()) But clearly I am missing a point here as this returns a promise. Shouldn't it print "hello"? On a similar note I am unclear as to whether a callback needs to be converted to a promise before wrapping it in async/await?

Wrapping promise in async/await

巧了我就是萌 提交于 2021-02-07 03:20:40
问题 I'm struggling a bit with async/await and returning a value from a Promise. function test () { return new Promise((resolve, reject) => { resolve('Hello') }) } async function c() { await test() } As I understood things I should be able to get a value by doing: console.log(c()) But clearly I am missing a point here as this returns a promise. Shouldn't it print "hello"? On a similar note I am unclear as to whether a callback needs to be converted to a promise before wrapping it in async/await?