Use tabs to set two (four) spaces, which are typically configurable in the IDE. Specific according to the actual requirements.
Badfunction () {???? var name;} Badfunction () {? var name;} Goodfunction () {?? var name;}
Leave a space in front of the left curly brace.
Badfunction Test () {console.log (' Test ');} Goodfunction Test () {console.log (' Test ');} Baddog.set (' attr ', {age: ' 1 year ', Breed: ' Samoyed '});//Gooddog.set (' attr ', {age: ' 1 year ', Breed: ' Husky '});
In the control statement (if, while etc), leave a space before the left parenthesis. Do not have spaces before the argument list of the function.
BADIF (test) {fight ();} GOODIF (test) {fight ();} Badfunction AAA () {console.log (' aaa! ');} Goodfunction AAA () {console.log (' aaa! ');}
Use whitespace to separate operators
Badvar x=y+5;//Goodvar x = y + 5;
Ending code with line breaks
Bad (function (global) {//... stuff ...}) (this);//Good (function (global) {//... stuff ...}) (this);
When you call a long method chain with indentation, you can emphasize that it is a method call, not a new statement.
bad$ (' #items '). Find ('. Selected '). Highlight (). End (). Find ('. Open '). Updatecount ();
good$ (' #items '). Find ('. Selected '). Highlight (). End (). Find ('. Open '). Updatecount ();
Leave blank lines before a statement block
BADIF (test) {return A;} Return a;//goodif (test) {return A;} return a;//Badvar obj = {a:function () {},b:function () {}};return obj;//Goodvar obj = {a:function () {},b:function () { }};return obj;
God bless!
"Learning Notes" JavaScript coding specification-blank