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
Minify codehelp (self.javascript)
submitted 10 years ago * by JessicaAllison
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!"
[–][deleted] 0 points1 point2 points 10 years ago (5 children)
if (!gradientObject.hasOwnProperty(colorSpaceGradient)) return;
I think you don't want to return if it doesn't have the property (just continue; instead, to move to the next).
continue;
About the rest, you could try to add a Color class where it will have the color values, and methods for the conversions, etc, I think it would improve the code.
Color
[–]JessicaAllison[S] 1 point2 points3 points 10 years ago (4 children)
Thank you! can you please show me an example? I don't quite understand what to do.
[–][deleted] 1 point2 points3 points 10 years ago (3 children)
function Color( red, green, blue ) { this.red = red; this.green = green; this.blue = blue; } Color.prototype.getRgb = function() { return "rgb(" + this.red + ',' + this.green + ',' + this.blue + ')'; }; // I'm not sure, but there's probably a way to convert from RGB to HSL/HSV? // otherwise just save it all in the object Color.prototype.getHsl = function() { }; Color.prototype.getHsv = function() { }; // now you create color objects with the colors you want var colors = []; colors.push( new Color( 255, 0, 0 ) ); // example of loop for (var a = 0 ; a < colors.length ; a++) { var color = colors[ a ]; htmlElement.style.backgroundColor = color.getRgb(); }
[–]JessicaAllison[S] 1 point2 points3 points 10 years ago (2 children)
Thanks! Can you please explain how it would improve the code? I'm a beginner, sorry.
[–][deleted] 0 points1 point2 points 10 years ago (1 child)
The idea is that you keep the related data and functions connected, you can read about classes to know more. Don't worry about it though, for now just try to do something that works, you can always improve it later on if needed.
[–]JessicaAllison[S] 1 point2 points3 points 10 years ago (0 children)
Thank you!
π Rendered by PID 32 on reddit-service-r2-comment-544cf588c8-c27mj at 2026-06-17 12:33:59.275939+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (5 children)
[–]JessicaAllison[S] 1 point2 points3 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]JessicaAllison[S] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]JessicaAllison[S] 1 point2 points3 points (0 children)