"Learning Notes" JavaScript coding specification-blank

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.