Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

JavaScript Guidelines

General Guidelines

In order to improve the clarity, quality and development time it is worth considering the following principles whenever possible:


Naming Conventions

Variables: Variables should be lowercase words separated by _.

const field_name = '...';

Functions: Functions should be camelCase. This is to easily distinguish between variables and functions.

const myFunction = () => { ... };

Capitalize "magic" strings and numbers:

const WARNING_MSG = 'This is a warning message';
const TRADE_TYPES = [{
    code: 'NOTOUCH',
    name: 'NoTouch',
}];

Modules: Module names and classes should be PascalCase.

const MyModule = (() => { ... })();

jQuery variables: jQuery variables should have a $ in the beginning to mark them.

const $test = $('#test');

JavaScript elements: JavaScript elements start with el_ for a similar effect.

const el_test = document.getElementById('test');

Boolean: Those variables which store a boolean value, should start with is_, has_, ...

const is_updated = true;
const has_crypto = false;

Form elements: Consider prefixes for form elements to make it more obvious what type of field they are, such as:

const fields = {
    txt_name  : { id: '#txt_name' },
    chk_tnc   : { id: '#chk_tnc' },
    ddl_agents: { id: '#ddl_agents' },
};

Commenting

Comments rules

  1. Always try to explain yourself in code first, comments should be seen as a "necessary evil".
  2. Don't add obvious noise.
  3. Don't comment out code. Just remove.
  4. Use as explanation of intent.
  5. Use as clarification of code.
  6. Use as warning of consequences.

Explanations: Feel free to add comments to explain any code that is confusing.

To do: Use TODO: ... comments anywhere that needs consideration or attention in the future.


Import Rules

Alphabetical ordering: The order is important; it should be sorted alphabetically according to path:

  • moment comes first as it's not a relative path.
  • s is before u so ./storage comes before ./utility.
  • Both applyToAllElements and createElement are from the same file, but a is before c
  • Unassigned require goes to the end

Combining require: When there are many functions being imported from the same file, consider combining it into one import line.

const Utility = require('./utility');

...

Utility.handleHash();
Utility.createElement('div');
...