Most important tips to make JavaScript pretty [closed]
CoffeeScript seems to be gaining traction from even non-python devs because of how it looks nice. I'm curious if anyone has a good tip(s) to make JavaScript look pretty by hand. I personally enjoy the JavaScript look, but just as an example part answer/part of an answer:
var a = 'b'开发者_如何学Python;
var foo = 'bar';
var hello = function(){ alert('world'); }
var lorem = 'ipsum';
Can (should) be written like:
var a = 'b'
, foo = 'bar'
, hello = function(){ alert('world'); }
, lorem = 'ipsum'
This isn't nessacarily a disussion, but a question of, "if you had a complete newbie at JavaScript as an intern, what are the most important methods of keeping your JavaScript clean and legible without any pseudo languages or parsers?"
What I always recommend to anyone who is interested in this kind of thing is: STICK TO WHAT YOUR TEAM DOES. If they use camelCase
for methods, you use it. If they use snake_case
for variables, you do it. If your team prefers spaces over tabs; use them.
Never go into a stablished team with standardized style changing things because it looks better unless it's causing heavy problems.
If you're not working on a team and you're interested on using a coding style; then use the style of the libraries you use the most.
- If you use
jQuery
stick to jQuery Coding Style Guidelines - If you use
Closure
Library use JavaScript Google Coding Style - If you use
MooTools
Library use MooTools Coding Style Guideline
Follow a style guideline.
I personally agree with most of the google style guide.
Use a ES5 or a library that introduces functional style sugar like underscore.
Writing solid consistent functional code in JavaScript should make your code look legible, terse and readable.
精彩评论