r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

Show parent comments

19

u/tjoskar Mar 19 '19

If we're going there, why not:

const sleep = ms => data => new Promise(resolve => setTimeout(resolve, ms, data))

😉

3

u/higherpublic Mar 19 '19 edited Mar 19 '19

No way. Such elegance!! How is data from the api call not getting passed in as the ms though?

Edit: never mind I see it now

1

u/TheKingdutch Mar 19 '19

TIL: about extra parameters for setTimeout. Thanks!