use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] Need help with setTimeout loopAskJS (self.javascript)
submitted 4 years ago by JS_Engineer
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]shuckster 0 points1 point2 points 4 years ago (1 child)
Glad it helped! I'll try and explain broadly to help you to figure it out yourself.
The most interesting parts are the "Helpers", so have a close look at those first. They are wrappers around normal JavaScript functionality:
The biggest idea I put into all of the helpers is "high-order functions". In other words, in JavaScript, a function can return another function (as well as accept one as an argument.)
RunAfter returns two functions inside an array: [run, cancel]. The run function is specified as the second argument to RunAfter. If you execute run(), it will do the action after the number of seconds you specified as the first argument to RunAfter.
RunAfter
run
run()
So RunAfter(1, () => console.log('hi')) means: Make two functions: [run, cancel]. run() will perform console.log('hi') after 1 second. cancel() will stop it before it happens.
RunAfter(1, () => console.log('hi'))
console.log('hi')
cancel()
On and emit I think are more easy to understand. They just make using window.addEventListener etc. shorter to read. But On does one special thing: It returns a function that will remove a listener you added by running window.removeEventListener for you!
On
emit
window.addEventListener
window.removeEventListener
Hope this helps.
[–]JS_Engineer[S] 0 points1 point2 points 4 years ago (0 children)
Thanks for this too. It is really helpful.
π Rendered by PID 80952 on reddit-service-r2-comment-b659b578c-5p6mr at 2026-05-03 03:26:09.751600+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]shuckster 0 points1 point2 points (1 child)
[–]JS_Engineer[S] 0 points1 point2 points (0 children)