"Notes" JavaScript coding specification-naming conventions

Source: Internet
Author: User
Tags stack trace

Avoid single-letter names and make names descriptive

Badfunction Q () {//... stuff ...} Goodfunction query () {//... Stuff..}

use camel spelling when naming objects, functions, and instances

Badvar objecttsssss = {};var This_is_my_object = {};function c () {}var u = New User ({name: ' Bob Parr '});//Goodvar this Ismyobject = {};function thisismyfunction () {}var user = new User ({name: ' Bob Parr '});<strong></strong>
when naming constructors or class names, use camel-style notation
Badfunction User (options) {this.name = Options.name;} var bad = new User ({name: ' Nope '});//goodfunction User (options) {this.name = Options.name;} var good = new User ({name: ' yup '});

use a front underline when naming private properties
badthis.__firstname__ = ' Panda '; this.firstname_ = ' Panda ';//goodthis._firstname = ' Panda ';

Use _this when saving this reference

Badfunction () {var = this;return function () {Console.log (self)};} Badfunction () {var = this;return function () {console.log (that);};} Goodfunction () {var _this = This;return function () {console.log (_this);};}

when naming a function, the following method facilitates the stack trace
Badvar log = function (msg) {Console.log (msg);};/ /goodvar log = function log (msg) {Console.log (msg);};


If the file is exported as a class, the filename should be consistent with the class name

File Contentsclass CheckBox {//...} Module.exports = checkbox;//in some other file//badvar checkbox = require ('./checkbox ');//Badvar checkbox = require ('./ Check_box ');//Goodvar CheckBox = require ('./checkbox ');

1:15 and let them is for lights in the firmament of the heaven to give light upon the earth:and it is so.

"Notes" JavaScript coding specification-naming conventions

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.