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


Groups > comp.lang.javascript > #33228

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 Sat, 06 May 2017 01:16:23 +0200
Organization PointedEars Software (PES)
Lines 50
Message-ID <4012654.cEBGB3zze1@PointedEars.de> (permalink)
References <oehnpk$i0b$1@news.albasani.net> <1885432.OBFZWjSADL@PointedEars.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1494026183 12683 eJwFwYEBwCAIA7CXqNjCzpkg/59gQhdUsUVtDgdrqnmsHQzLk921KPJ39DEXyycaFqi8330ZVhD1 (5 May 2017 23:16:23 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Fri, 5 May 2017 23:16:23 +0000 (UTC)
User-Agent KNode/4.14.2
X-NNTP-Posting-Host eJwNwokRwDAIA7CVIMY841By7D9CehLh6hPmdOP+JvxgD0KMCpGVvnsNu83qjppM0CS/21r1AAo6EKI=
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
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 eJwNy8EBwCAMAsCVEg2I4zRW9h+hvf9hMnlWESwY5vLTo8sKHBOKE85I7Oq9SMeunC/lVCatPwl1PfuOAX08vRSM
Cancel-Lock sha1:OaF8He0JGTlqXkKRMu+rbigwMP4=
Xref csiph.com comp.lang.javascript:33228

Show key headers only | View raw


Thomas 'PointedEars' Lahn wrote:

> Martin Honnen wrote:
>> If I simply use
>> 
>>    <input type="button" value="test"
>>     onclick="var response = await fetch(location.href);">
>> 
>> I get an error "Unexpected identifier".

Me too.  To be precise, a SyntaxError exception with that message is thrown
and not caught.
 
>> 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();"

Both work in

| Chromium	57.0.2987.98 (Developer Build) Built on 8.7, running on Debian stretch/sid (64-bit)
| Revision	a6a06b78087c9fdb4b12fe0ac1b87fdc10179f8b
| OS                Linux 
| JavaScript	V8 5.7.492.63
| […]
| User Agent	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36
| Command Line	/usr/lib/chromium/chromium --disk-cache-size=44040192 --show-component-extension-options --ppapi-flash-path=/usr/lib/pepperflashplugin 
nonfree/libpepflashplayer.so --ppapi-flash-version=23.0.0.207 --flag-switches-begin --ignore-gpu-blacklist --flag-switches-end

(<chrome://version>)

So if I had to use one of them, I would use the first one (the AFE).

However, why would one want to produce spaghetti code?

-- 
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 | 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