Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #33225

Re: How would using await be possible in an event handler content attribute?

Path csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: How would using await be possible in an event handler content attribute?
Date Fri, 05 May 2017 20:02:21 +0200
Organization PointedEars Software (PES)
Lines 46
Message-ID <1885432.OBFZWjSADL@PointedEars.de> (permalink)
References <oehnpk$i0b$1@news.albasani.net>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace solani.org 1494007341 31378 eJwFwQkBwDAIA0BLfAlMDqXDv4TewamcDIKBxYbys5qNX8PbxeNoj5Gny5h2j62MVEqhcfcBB3MQkA== (5 May 2017 18:02:21 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Fri, 5 May 2017 18:02:21 +0000 (UTC)
User-Agent KNode/4.14.2
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-User-ID eJwFwQkBwDAIA0BL0BJY5fDFv4Td4bp6hzncQNDVpMDns4pJ9rx456vv8KxlcmWqJVGlezJYVyWgGvRG2A9vYRYX
Cancel-Lock sha1:my6P2tH/+jnHYTF65MQY7yjfh+s=
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
X-NNTP-Posting-Host eJwFwQkBACAIA8BM0/HFAYT+EbyTq9A2qihlZYn0VrgMZ9WjrF9l2RQK2XvfYbxk2uA04gMvLBHs
Xref csiph.com comp.lang.javascript:33225

Show key headers only | View raw


Martin Honnen wrote:

> As far as I understand, to use the "await" operator
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
> I need to declare the function containing it as "async" e.g.
> 
> async function foo(url) {
>    var response = await fetch(url);
>    var text = await response.text();
>    document.getElementById('input1').value = text;
> }

Boy, are they tweaking the language these days.
 
> I wonder whether there is any way inside HTML to specify that an event
> handler content attribute is not a function body but an "async" function
> body so that it is possible to use "await" inside the event handler
> content attribute.
> 
> If I simply use
> 
>    <input type="button" value="test"
>     onclick="var response = await fetch(location.href);">
> 
> I get an error "Unexpected identifier".
> 
> Is there any way to designate an event handler content attribute as an
> async function body?

I do not know of any.  The obvious solution might be

  onclick="(async function () {
    var response = await fetch(location.href);
  }())"

or

  onclick="async function blub () {
    var response = await fetch(location.href);
  }; blub();"

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How would using await be possible in an event handler content attribute? Martin Honnen <martin.honnen@gmx.de> - 2017-05-05 13:30 +0200
  Re: How would using await be possible in an event handler content attribute? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-05 20:02 +0200
    Re: How would using await be possible in an event handler content attribute? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-06 01:16 +0200

csiph-web