diff --git a/README.md b/README.md index 3b23198..314a72f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ This document contains guides that *I* defined and follow when building things. # Contents - - [Variable declarations](#variable-declarations-pencil) - [Variables](#variables-speech_balloon) @@ -37,10 +36,8 @@ This document contains guides that *I* defined and follow when building things. - [Project naming](#project-naming) ## Variable declarations :pencil: - ### Variables :speech_balloon: - Using `var` in general or `let` when they should be accesible only in specific blocks (e.g. `if`). ```js @@ -58,10 +55,8 @@ if (...) { /* do something with baz */ } ``` - ### Constants :triangular_flag_on_post: - Using `const`. The constant names are written with UPPERCASE letters. I also use `const` when including libraries using `require` and when they should not be changed. In this case, the names will not be with caps. ```js @@ -74,15 +69,12 @@ const PI = Math.PI , MY_CONSTANT = 42 ; ``` - ### Globals :earth_africa: - I define globals when there is no commonjs environment (this is actually handled by [`dist-it`](https://github.com/IonicaBizau/dist-it). When I manually define globals, I do that using `window.MyGlobal` (on the client) and `global.MyGlobal` (on the server). ## Semicolons :pencil2: - I *use* semicolons. Almost always. ```js @@ -97,10 +89,8 @@ class Foo { ... } ``` - ## Method and property definitions :paperclip: - I use the ES6 `class` for creating classes. ```js @@ -114,10 +104,8 @@ class Person { } } ``` - ## Deleting properties :x: - I nullify the properties when that's fine: ```js @@ -127,16 +115,13 @@ var foo = { foo.bar = null; ``` - However, I use the `delete` keyword when I really want to delete them. ```js delete foo.bar; ``` - ## `eval()` - `eval` is evil. :rage: Do not use it. However I use it in some test files and in places where I have to execute the JavaScript code provided by the user. @@ -144,7 +129,6 @@ For converting strings to JSON, use `JSON.parse(strObj)`. ## Iterating objects and arrays - For arrays, most of times, I use the `forEach` function: ```js @@ -153,7 +137,6 @@ arr.forEach(c => { }); ``` - However, using `for` loops is fine too: ```js @@ -165,7 +148,6 @@ for (var i = 0; i < arr.length; ++i) { } ``` - For objects, I use the following style: ```js @@ -175,7 +157,6 @@ Object.keys(obj).forEach(k => { }); ``` - To simplify this, I created [`iterate-object`](https://github.com/IonicaBizau/iterate-object), which abstracts this functionality: ```js @@ -184,10 +165,8 @@ iterateObject(obj, (value, key) => { // do something }); ``` - ## Multiline strings :guitar: - I use backticks to create multiline strings: ```js @@ -197,15 +176,12 @@ aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat New line again...`; ``` - ## Modifying prototypes of built-in objects :shit: - Just don't, unless that's the scope of the library. ## Naming things :thought_balloon: - Using camel case notation for variables, in general. For constructors I capitalize the variable name (e.g. `EventEmitter`). ```js @@ -240,10 +216,8 @@ var obj = { }; obj.methodA = function () {...}; ``` - ## Curly braces :curly_loop: - Open the curly brace at the end of the line. Always put the instructions between curly braces, even there is only one instruction. ```js @@ -254,10 +228,8 @@ if (expr) { instr3; } ``` - ## Array and Object Initializers :file_folder: - See examples. ```js @@ -285,10 +257,8 @@ var obj1 = { , age: 20 }; ``` - ## Commas - Put commas at the beginning of the line, not at the end. ```js @@ -305,10 +275,8 @@ var obj = { , y: 2 }; ``` - ## Blank lines - Group the instructions inserting some blank lines where it's needed. ```js @@ -318,10 +286,8 @@ bar(x); foo(y); bar(y); ``` - ## Binary and Ternary operators - See examples. ```js @@ -342,20 +308,16 @@ var c = another_long_condition_here : or_another_some_long_value ; ``` - ## Quotes :speech_balloon: - Double quotes, with some exceptions when single quotes are used. ```js var foo = "\"Hello\", he said."; var jQuerySelector = "div.myClass[data-foo='bar']"; ``` - ## Comments :notes: - Put relevant comments. The comments start with uppercase letter. ```js @@ -368,7 +330,6 @@ const lib1 = require("lib1") const FOURTY_TWO = 42; ``` - Use JSDoc comments for functions and methods. ```js @@ -387,7 +348,6 @@ function sum (a, b) { }; ``` - I use the [`blah` tool](https://github.com/IonicaBizau/blah) to generate documentation. ```sh @@ -395,15 +355,12 @@ $ npm install -g blah $ blah --readme $ blah --docs some-file.js ``` - ## Project naming - I use [`name-it`](https://github.com/IonicaBizau/name-it) to generate project names. ## Project licenses - I :sparkling_heart: open-source! I prefer the MIT license.