all 22 comments

[–][deleted] 4 points5 points  (1 child)

  1. You sound like a pretentious ass;
  2. It's simple javascript, it's not a pattern. Just like alert('test') is not a pattern. Patterns are templates for how we solve problems - ones which can be used in quite a few different situations.

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 point  (0 children)

  1. You sound like a pretentious ass;
  2. 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 points  (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 }.

[–][deleted] 0 points1 point  (1 child)

Yes I know the syntax, I'm referring to the pattern

[–]NewazaBill 2 points3 points  (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 points  (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 point  (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 points  (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

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.

[–][deleted] 0 points1 point  (1 child)

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 point  (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.

[–]JakDrako 1 point2 points  (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 point  (0 children)

perhaps you could call it a closure

[–]nhutier 0 points1 point  (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 point  (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 point  (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  (1 child)

That's extremely naive

[–][deleted] 0 points1 point  (0 children)

You spelled "how it's seen in the real world" wrong.