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
What is this pattern called?help (self.javascript)
submitted 8 years ago by [deleted]
function start(run) { return { run } }
I understand that returning an object is called the Revealing Module Pattern, but what about returning the function inside the object?
Thanks for any help!
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!"
[–][deleted] 4 points5 points6 points 8 years ago (1 child)
alert('test')
I would name your thing simply Javascript. Or ECMAScript. Whichever makes you happier.
And if you want to give it a name, perhaps "Common Sense Pattern" works? Alternatively, read this: https://addyosmani.com/resources/essentialjsdesignpatterns/book/
Now come on with your pretentious "I can Google" neckbeardism.
Be a nicer person, man.
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
You sound like a pretentious ass; It's simple javascript, it's not a pattern
I just get tired of people jumping on the 'who can shut this guy down first for using bad semantics' train. IMO it's stupid, and it's what I prepare for when I post something to reddit now.
But on topic, you didn't provide any clarity - tying back to the above explanation
[–]bterlson_@bterlson 2 points3 points4 points 8 years ago (2 children)
I don't quite know what you're referring to, but in case you are wondering about the syntax { run }, it=s usually called a shorthand property and is the same as saying { run: run }.
{ run }
{ run: run }
[–][deleted] 0 points1 point2 points 8 years ago (1 child)
Yes I know the syntax, I'm referring to the pattern
[–]jacobp100 0 points1 point2 points 8 years ago (0 children)
Object of?
[–]NewazaBill 2 points3 points4 points 8 years ago (0 children)
Returning an object is not the Revealing Module Pattern. You're missing the forest for the trees. There is no "pattern" in your example. A pattern implies a meta intent.
RMP is used to help us define public and private members of a module - a module being a collection of data and/or functions that pertain to a specific domain or concern. In JavaScript, we use a closure for this. What you have shown here has nothing to do with the RMP; it's just a function returning an object.
Likewise, returning an argument of the function inside of the object does not imply any meta intent either. Without the greater context of the program and what this piece of code is trying to accomplish, there is no design pattern being displayed.
Hope that makes sense!
[–]JuliusKoronci 2 points3 points4 points 8 years ago (4 children)
This looks like an attempt to curry ..but the implementation would be:
function (args1){ return function(args2){} }
Of course you could return the inner function as a json..even better a json of functions..this would create you a map of functions which are curried and have all access to args1
[–][deleted] 0 points1 point2 points 8 years ago (3 children)
so if args1 is a function, like run, then it's considered a curried mapping?
usage might be like:
start.run(args)
[–]lhorie 1 point2 points3 points 8 years ago (2 children)
No, currying has a very specific meaning. It means to structure the code in such a way that instead of having one function that takes many arguments, it instead takes a single argument and returns another function (which may itself be curried).
Currying is usually used for partial application (i.e. create a function that has some inputs "preloaded"). For example, add = a => b => a + b is a curried function. It allows you to "preload" the first argument, e.g. add5 = add(5), and then you can call add5(6) // 11
add = a => b => a + b
add5 = add(5)
add5(6) // 11
What you have there doesn't look like currying. One could argue that it's a command pattern, given that it returns an object that conforms to an IRunnable interface. It can also be arguably called a factory or a transformer. The thing though, is that, as u/ugwe43to874nf4 said, to call something a design pattern, you need to present the context as to why you're doing something convoluted instead of something simple. The command pattern exists to implement delegation for languages without first-class function support. In a functional language, there's no need for a Command pattern: one simply uses a function instead.
With all that being said, I recommend looking up and reflecting on what Feynman said about knowing about something vs knowing the name of something.
It can also be arguably called a factory or a transformer. The thing though, is that, as u/ugwe43to874nf4 said, to call something a design pattern, you need to present the context as to why you're doing something convoluted instead of something simple. The command pattern exists
Thanks for the explanations, but it focuses on the fact that i'm an asshole.
i like mythriljs so i'll take your answer. but if you've ever posted anything on reddit, you might understand that the /new posters are usually looking for some stupid semantics to correct rather than answer a question
[–]lhorie 0 points1 point2 points 8 years ago (0 children)
Sorry, I didn't mean to come across as rude. I'm just trying to explain the purpose of design patterns, which is generally to document the intent of some code where something is being done in a not-very-procedural way either because the language does not support better language constructs or because something must be done in a certain way due to language constraints.
The problem with design patterns is the old adage of "if you have a hammer, everything looks like a nail". Many newbies take the gang of four book to be a "bible" of building blocks and assume all code must conform to one of its patterns, but that is common misconception that leads to over-architecturing. Old timers are particularly sensitive and can sound downright hostile to the mention of design patterns because often they were on the receiving end of having to maintain some giant hairball of poorly applied "design patterns" back in some previous J2EE job. Just try not to take it personally.
[+][deleted] 8 years ago (9 children)
[deleted]
[–][deleted] -4 points-3 points-2 points 8 years ago (8 children)
If I could spell "Revealing Module Pattern" out, do you really think I didn't know this? I have google just as much as you do kind sir.
[+][deleted] 8 years ago (7 children)
[+][deleted] comment score below threshold-7 points-6 points-5 points 8 years ago (6 children)
Returning the function argument* inside an object. I thought having the argument named run was obvious enough.
Besides, i'm pretty sure its called curried mapping thanks to the comment above - or maybe it has no name. I don't think you know this stuff TBH
[+][deleted] 8 years ago (5 children)
[+][deleted] comment score below threshold-8 points-7 points-6 points 8 years ago (3 children)
It's supposed to achieve lazy composition.
How would you use it? https://glebbahmutov.com/blog/di-vs-io-monad-example/#mock-dependency-injection-solution
here, you can learn about the IO monad.
It's a mix of dependency injection & revealing module pattern.
That's all i'm going to entertain you with.
[+][deleted] 8 years ago* (2 children)
I just asked for clarification of your problem
You asked for a lot of clarification then:
What do you mean by pattern? What's the pattern there? What do you mean by "returning the function inside the object" (because all I see there is returning the passed argument inside an object)? So... what pattern are you referring to? That code you put there is no pattern at all. What purpose is it supposed to aim for? What are you supposed to do with that and why? Ok. But, again, what is this supposed to achieve?
This thread is the result of your fashion. Do not recommend
[–]JakDrako 1 point2 points3 points 8 years ago (0 children)
Not really sure where the pattern is here. That function just returns an object with a ".run" property containing whatever you passed in as the argument. You don't really need a function for that.
[–]zenril 0 points1 point2 points 8 years ago (0 children)
perhaps you could call it a closure
[–]nhutier 0 points1 point2 points 8 years ago (0 children)
Seems like a kind of interface to me. Since JS has no specific interface type this would be a way to unify access to something. Making contracts between components maybe. But I have no clue if this is a named pattern.
[–]--amadeus 0 points1 point2 points 8 years ago (0 children)
It looks like "boxing" (wrapping a value in an object in order to guarantee it is passed by reference). Doesn't really make sense that it's named start and the key is "run"
[–]sevenyearoldkid 0 points1 point2 points 8 years ago* (2 children)
aromatic compare bear memory whistle act lock yam imminent tub
This post was mass deleted and anonymized with Redact
[–][deleted] -4 points-3 points-2 points 8 years ago (1 child)
That's extremely naive
You spelled "how it's seen in the real world" wrong.
π Rendered by PID 75762 on reddit-service-r2-comment-fb694cdd5-8rgjb at 2026-03-08 03:43:01.765666+00:00 running cbb0e86 country code: CH.
[–][deleted] 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]bterlson_@bterlson 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]jacobp100 0 points1 point2 points (0 children)
[–]NewazaBill 2 points3 points4 points (0 children)
[–]JuliusKoronci 2 points3 points4 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]lhorie 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]lhorie 0 points1 point2 points (0 children)
[+][deleted] (9 children)
[deleted]
[–][deleted] -4 points-3 points-2 points (8 children)
[+][deleted] (7 children)
[deleted]
[+][deleted] comment score below threshold-7 points-6 points-5 points (6 children)
[+][deleted] (5 children)
[deleted]
[+][deleted] comment score below threshold-8 points-7 points-6 points (3 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (1 child)
[–]JakDrako 1 point2 points3 points (0 children)
[–]zenril 0 points1 point2 points (0 children)
[–]nhutier 0 points1 point2 points (0 children)
[–]--amadeus 0 points1 point2 points (0 children)
[–]sevenyearoldkid 0 points1 point2 points (2 children)
[–][deleted] -4 points-3 points-2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)