Why does Javascript (ES.next) force me to declare a function as async if I want to use await? -
it seems compiler / parser should smart enough detect if function uses await
automatically becomes async
function.
why forced type async
keyword? adds clutter , there many times forget add , error , have go , add it.
would there disadvantage having compiler automatically promote function async
when sees await
, save hassle of dealing it?
compare async functions es6 generator functions , pretty obvious:
function* x() {} // generator function without 'yield' object.getprototypeof(x); // returns generatorfunction
generator functions inherently different traditional functions, not need have yield
expression in body. there a bug in es6 proposal stated syntax error if generator function not contain yield
, fixed:
one important use case prototyping dummy generator. or case comment out yield debugging. shouldn't render program illegal.
the same holds async functions: according the draft, async function not required have awaits
in body while still behaving different traditional function.
let's comment await
out. should interpreter parse async function traditional function , possibly break whole code? better not.
Comments
Post a Comment