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?

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 2017-05-05 20:02 +0200
Organization PointedEars Software (PES)
Message-ID <1885432.OBFZWjSADL@PointedEars.de> (permalink)
References <oehnpk$i0b$1@news.albasani.net>

Show all headers | 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