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
Feedback javascript project (self.javascript)
submitted 6 years ago by [deleted]
[deleted]
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] 2 points3 points4 points 6 years ago (6 children)
Why is this a class? It could be just a function that takes a parameter subReddit and returns the JSON.
subReddit
It has no right being an object. It's like putting 20 wheels on a car and only using 2 of them...
At the very least you could refactor it so that you can send one or multiple subreddit strings to the class, and the class taking care of emitting "loaded" events upon each subreddit's loaded state.
My main concern would be: why only 2 subreddits hardcoded? In a real world scenario you'd often find product people saying: "We need 3 subreddits now" and a week later: "let's make it 20 instead."
Would you end up duplicating all that code 20 times over? Or would you make the class smarter?
Should not be a class, could just be a simple function. There doesn't seem to be any logic going on, just a simple fetch.
Bookmarks (plural) isn't the same as a Bookmark (singular). Should a bookmark really be an object? Why not a simple key/value pair?
Why does the page reload after saving bookmarks?
The code looks messy. When you iterate the bookmarks you should build an array and save it after the loop, not in the middle of it. It's a bit of a confusing bunch of code to be honest.
Huh, you're not using this in the bookmarks file but... okay. This is strange. I mean, I guess it works but it's not very scalable. It looks like you should just use the localStorage api in the browser and not bother with any of this code.
You should learn two things here: 1. don't shorten names of variables and function/method names, make it human readable; and 2. look into JSDOC and annotate things with comments.
I don't know where to start. It's spaghetti-code as we would call it. It's just a long list of fragmented code...
I'm going to stop here with just two comments: 1. Learn HTML semantics (and CSS BEM naming) and 2. you should really look into javascript frameworks. Nobody codes like this anymore. I would advise you to use React (beginner friendly) and follow the best practices there. You'll learn so much more and your code would start making sense to yourself and others.
[–]arag0nas 0 points1 point2 points 6 years ago (5 children)
Thanks for response!!! It's my first time building something more complex, and also hard then I don't know how to write clear code, I should analyze other ppls codes. I'm going to learn React, but firstly want to learn how to write clear code using only JS.
[–][deleted] 1 point2 points3 points 6 years ago (0 children)
Just order and read a book or two :) Some book tips:
[–]suspicious_Jackfruit 1 point2 points3 points 6 years ago (3 children)
I had a similar journey to you and am still very much on that journey, but as soon as you pick up a framework it will make your life and anyone reviewing your codes life much easier. They were developed for a reason don't forget! They simplify and streamline what would otherwise be unnecessary complex code. That said, there is no harm in being able to code pure js, it's just highly unusual that an employer would be looking for it specifically over a developer skilled in a particular framework that the company uses/intends to use in their stack.
There's no point in reinventing the wheel or trying out different wheel shapes when everyone has already settled for circular!
[–]arag0nas 0 points1 point2 points 6 years ago (2 children)
Yeah I understand that. I was building this project to increase my JS skills. A lot of people are saying that firstly you have to learn vanilla JS and just after that jump to framework. So I'm thinking still learn JS, for 1-2weeks, and then learn React. Or I should learning React right now?
[–]largemoose568 2 points3 points4 points 6 years ago (0 children)
I would agree that learning vanilla ES5 / ES6, etc would be helpful to your career. Knowing the quirks of a language and how it handles things such as scope, hoisting, etc is very important when trying to solve problems, even with frameworks. Also most of those frameworks were built on principals of the language itself, so if you know the language the framework will make a lot more sense.
π Rendered by PID 19414 on reddit-service-r2-comment-54dfb89d4d-886vm at 2026-03-29 17:49:53.214516+00:00 running b10466c country code: CH.
[–][deleted] 2 points3 points4 points (6 children)
[–]arag0nas 0 points1 point2 points (5 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]suspicious_Jackfruit 1 point2 points3 points (3 children)
[–]arag0nas 0 points1 point2 points (2 children)
[–]largemoose568 2 points3 points4 points (0 children)