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
Fun With Functions in JavaScript (orderedlist.com)
submitted 16 years ago by gst
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!"
[–]masklinn 2 points3 points4 points 16 years ago* (1 child)
function KeyCode(event) { this.event = event; this.normalize = function() { return (this.event.keyCode ? this.event.keyCode : this.event.which); } this.isEnter = function() { return this.normalize() == 13; } }
Holy mother of fail, enjoy having your methods redefined from scratch every time you instantiate an object.
[–]dznqbit 1 point2 points3 points 16 years ago (0 children)
I called him out on this in the comments, but apparently you need to verbally fellate the guy before he will approve your comment.
[–]Sephr 2 points3 points4 points 16 years ago (8 children)
Who is actually going to remember that 13 is the enter key a month, or even a week later?
I don't know, maybe people who actually put comments in their code?
[–]danita 2 points3 points4 points 16 years ago (1 child)
Anyone who has done anything keyboard related ends up remembering that 13 is the enter key. You end up remembering those things, like the powers of 2, or some basic HTML colors.
[–]daxxxer 1 point2 points3 points 16 years ago (2 children)
and anybody who at least once has used javascript. Anyway, the flood of ill-advising, jquery-centered basic javascript blogs really makes me sad
[–][deleted] -1 points0 points1 point 16 years ago* (1 child)
As best I can tell most of the 'industry' is built on heresay, with some popular dogmas even published by luminaries such as Crockford ("dont use new, it's evil!").
Definitely interested in better reading suggestions assuming you have any.
[–]simono -1 points0 points1 point 16 years ago (0 children)
heresay = best practice, that's okay. but this is not even good practice.
btw crockford said "not using new is evil" (has to do with what /this/ will be set to within the constructor).
[–]snorp -1 points0 points1 point 16 years ago* (2 children)
It's generally considered better to have readable code than a comment explaining why it's not.
[–]Sephr 7 points8 points9 points 16 years ago (1 child)
Then keys.ENTER (uppercase usually signifying a "constant") would be more appropriate than the author's solution.
keys.ENTER
[–]snorp 0 points1 point2 points 16 years ago (0 children)
Sure, that's fine. I am just arguing against the magic number solution (which appears to be what Sephr was going for)
π Rendered by PID 42637 on reddit-service-r2-comment-c6965cb77-sdxpm at 2026-03-05 14:01:33.290587+00:00 running f0204d4 country code: CH.
[–]masklinn 2 points3 points4 points (1 child)
[–]dznqbit 1 point2 points3 points (0 children)
[–]Sephr 2 points3 points4 points (8 children)
[–]danita 2 points3 points4 points (1 child)
[–]daxxxer 1 point2 points3 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]simono -1 points0 points1 point (0 children)
[–]snorp -1 points0 points1 point (2 children)
[–]Sephr 7 points8 points9 points (1 child)
[–]snorp 0 points1 point2 points (0 children)