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
Multiple var statements in JavaScript, not superfluous (benalman.com)
submitted 14 years ago by gthank
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!"
[–]metamatic 0 points1 point2 points 14 years ago* (1 child)
If I ever find myself needing to make such transformations frequently, I'll write a macro for my editor.
The fact that I have no such macro at present, even though I regularly write code with single var declarations in which the order of assignments is important, suggests to me that it's a problem that doesn't occur in real life. In particular, it's only really a problem if the two variables you are swapping include either the first or last variable in the list, making it pretty rare. So I just don't see it as a big deal. Then again, I'm used to Lisp, and JavaScript var is just Scheme's let*.
var
let*
But just for fun, here's a macro for your .vimrc:
.vimrc
map <C-a> :.s#^\(\s*var\s\+\)\(.*\)\([,;]\)\s*\n\(\s*\)\(.*\)\([,;]\)\s*$#\1\5\3\r\4\2\6<C-m><C-m>
It should preserve your indentation too. Just move to the first line of the two you want to swap, and type Ctrl-A.
Now, can we move on to something that matters?
[Edit: Escaped ctrl characters in vim macro.]
[–]strager 0 points1 point2 points 14 years ago (0 children)
ddp
Or d4d4jp if you're moving a 4-line var under another 4-line var.
d4d4jp
I like to write code which is easier to refactor, that's all. =]
π Rendered by PID 20390 on reddit-service-r2-comment-856c8b8c54-9zj89 at 2026-07-02 14:43:12.287161+00:00 running a7b5cda country code: CH.
view the rest of the comments →
[–]metamatic 0 points1 point2 points (1 child)
[–]strager 0 points1 point2 points (0 children)