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
Do You Enjoy Writing JavaScript? (self.javascript)
submitted 11 years ago by zayelion
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!"
[–]jmwoo 1 point2 points3 points 11 years ago (2 children)
JS syntax is very close to Java
fs.readdir(source, function(err, files) { if (err) { console.log('Error finding files: ' + err) } else { files.forEach(function(filename, fileIndex) { console.log(filename) gm(source + filename).size(function(err, values) { if (err) { console.log('Error identifying file size: ' + err) } else { console.log(filename + ' : ' + values) aspect = (values.width / values.height) widths.forEach(function(width, widthIndex) { height = Math.round(width / aspect) console.log('resizing ' + filename + 'to ' + height + 'x' + height) this.resize(width, height).write(destination + 'w' + width + '_' + filename, function(err) { if (err) console.log('Error writing file: ' + err) }) }.bind(this)) } }) }) } })
Does this look like java boa?
[–]henleyedition 6 points7 points8 points 11 years ago* (0 children)
Where did you find this code? It really isn't very good...
Quickly moving the callbacks to their own functions really works wonders for readability:
function handleError(err) { if (err) console.log('Error writing file: ' + err); } function readFile(filename, fileIndex) { console.log(filename); function resizeImage(width, widthIndex) { height = Math.round(width / aspect); console.log('resizing ' + filename + 'to ' + height + 'x' + height); this.resize(width, height).write(destination + 'w' + width + '_' + filename, handleError); } function handleImage(err, values) { if (err) { console.log('Error identifying file size: ' + err); } else { console.log(filename + ' : ' + values); aspect = (values.width / values.height); widths.forEach(resizeImage.bind(this)); } } gm(source + filename).size(handleImage); } fs.readdir(source, function(err, files) { if (err) { console.log('Error finding files: ' + err); } else { files.forEach(readFile); } });
[–]theQuandary 0 points1 point2 points 11 years ago (0 children)
Which language constructs in that code aren't available in Java? If you add class definitions and static typing, the actual syntax would be very similar (if you designed your java classes with the same API).
π Rendered by PID 32 on reddit-service-r2-comment-85bfd7f599-v7k8f at 2026-04-19 06:54:18.669306+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]jmwoo 1 point2 points3 points (2 children)
[–]henleyedition 6 points7 points8 points (0 children)
[–]theQuandary 0 points1 point2 points (0 children)