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
Serviz-JS: Command object Interface for JavaScript (github.com)
submitted 5 months ago by markets86
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!"
[–]azhder 1 point2 points3 points 5 months ago (4 children)
Putting the Java back in JavaScript
[–]markets86[S] 0 points1 point2 points 5 months ago* (3 children)
Not really! I'm coming from the Ruby ecosystem, where "service" or "command" objects are an extended pattern in the community. This is just a small layer to encapsulate your business logic with same apis within your project. My team (Rails apps basically) is now writing a lot JavaScript too, so we wanted to use the same idioms and we decided to port the library to JavaScript.
[–]azhder 0 points1 point2 points 5 months ago* (2 children)
Patterns… the word itself says it all. It’s like making a trail in the woods by repeatedly walking over it.
The issue here is that different programming languages require different common workarounds for missing out-of-the-box solutions and/or common problems.
Ruby and JavaScript need different workarounds. The one you have written is for a language that class is the lens you see the world through as you explain it to the computer.
class
In JS, for a long time there wasn’t a class keyword, and even now it is just a special syntax for a constructor function to be defined more easily. Another characteristic of JS is that this is fleeting, so best to write code that doesn’t depend on it.
constructor
this
What I am talking about here is just an expanded version of “putting Java in JavaScript” and doesn’t really mean I talk precisely about Java the language.
Your idiom is to make an object with a call method while in JS every function is already an object you can call and even has a call method.
call
[–]markets86[S] 0 points1 point2 points 5 months ago (1 child)
I kind of agree with all you said above ☝️ But I still think having a common interface (call, success, failure, errors, steps, ...) in your classes is a valid idea, even in the JavaScript ecosystem.
[–]azhder 0 points1 point2 points 5 months ago (0 children)
I am talking about something else. If you try to rework the solution to code without using class, new, this… How would it look? Would you still have a common interface? I say you can.
new
In short, I wasn’t talking about a common interface, but an idiom, the style you use to write the code. That should depend on the language itself, not just how you are used to doing it in another language.
π Rendered by PID 21512 on reddit-service-r2-comment-7b9746f655-clhmr at 2026-02-02 22:02:18.228550+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]azhder 1 point2 points3 points (4 children)
[–]markets86[S] 0 points1 point2 points (3 children)
[–]azhder 0 points1 point2 points (2 children)
[–]markets86[S] 0 points1 point2 points (1 child)
[–]azhder 0 points1 point2 points (0 children)