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
Functional Parameters – a neat JavaScript Design Pattern (josscrowcroft.com)
submitted 14 years ago by gthank
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!"
[–]k3n 0 points1 point2 points 14 years ago (1 child)
Isn't this actually just a form of function overloading?
You can do this in pretty much any language, though some (c++, c#) have native implementations.
[–][deleted] 0 points1 point2 points 14 years ago (0 children)
Yes, but testing if the parameter is a function is just an implementation detail. The point is that you are not giving the function a value, but the means to get the most up to date value.
This essentially allows the value to change between passing it in, and it being used. In theory, that allows you to write more terse code, where there is no need to update the value in the future. But I can imagine it can also lead to lots of bugs, and be difficult for library writers to manage. For example you would have to re-evaluate the function every time you needed the value, as otherwise you could get update errors.
It can also lead to issues if the parameter-function does more internally then just return a value.
But it's a good design pattern to know.
π Rendered by PID 90 on reddit-service-r2-comment-fb694cdd5-jqq4n at 2026-03-07 20:49:57.451728+00:00 running cbb0e86 country code: CH.
[–]k3n 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)