[Study Notes] JavaScript coding specifications-blank, learning notes javascript

Source: Internet
Author: User

[Study Notes] JavaScript coding specifications-blank, learning notes javascript

Use a tab to set two (4) spaces. This function can be configured in IDE. According to actual requirements.

// badfunction() {∙∙∙∙var name;}// badfunction() {∙var name;}// goodfunction() {∙∙var name;}


Leave a space before the braces on the left.
// 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 bracket. Do not have spaces before the function parameter list.

// badif(test) {fight ();}// goodif (test) {fight();}// badfunction AAA() {console.log ('AAA!');}// goodfunction AAA() {console.log('AAA!');}

Use spaces to separate operators

// badvar x=y+5;// goodvar x = y + 5;


End code with a line break

// bad(function(global) {// ...stuff...})(this);// good(function(global) {// ...stuff...})(this);↵

Use indentation when calling a long method chain. It can be emphasized that it is a method call rather than 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 statement Blocks

// 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;


And the earth brought forth grass, and herb yielding seed after his kind, and the tree yielding fruit, whose seed was in itself, after his kind; and God saw that it was good.

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.