diff --git a/README.md b/README.md index dbafdc488d..a854681072 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,17 @@ -# Airbnb JavaScript Style Guide() { +# JavaScript Style Guide () { *A mostly reasonable approach to JavaScript* - ## Table of Contents - 1. [Types](#types) 1. [Objects](#objects) 1. [Arrays](#arrays) 1. [Strings](#strings) 1. [Functions](#functions) 1. [Properties](#properties) 1. [Variables](#variables) - 1. [Hoisting](#hoisting) 1. [Conditional Expressions & Equality](#conditionals) + 1. [Control Flow](#control-flow) 1. [Blocks](#blocks) 1. [Comments](#comments) 1. [Whitespace](#whitespace) @@ -24,53 +22,12 @@ 1. [Accessors](#accessors) 1. [Constructors](#constructors) 1. [Events](#events) - 1. [Modules](#modules) 1. [jQuery](#jquery) - 1. [ES5 Compatibility](#es5) - 1. [Testing](#testing) - 1. [Performance](#performance) 1. [Resources](#resources) - 1. [In the Wild](#in-the-wild) - 1. [Translation](#translation) 1. [The JavaScript Style Guide Guide](#guide-guide) 1. [Contributors](#contributors) 1. [License](#license) -## Types - - - **Primitives**: When you access a primitive type you work directly on its value - - + `string` - + `number` - + `boolean` - + `null` - + `undefined` - - ```javascript - var foo = 1, - bar = foo; - - bar = 9; - - console.log(foo, bar); // => 1, 9 - ``` - - **Complex**: When you access a complex type you work on a reference to its value - - + `object` - + `array` - + `function` - - ```javascript - var foo = [1, 2], - bar = foo; - - bar[0] = 9; - - console.log(foo[0], bar[0]); // => 9, 9 - ``` - - **[[⬆]](#TOC)** - ## Objects - Use the literal syntax for object creation. @@ -163,7 +120,7 @@ - To convert an array-like object to an array, use Array#slice. ```javascript - function trigger() { + function trigger () { var args = Array.prototype.slice.call(arguments); ... } @@ -190,7 +147,8 @@ var fullName = 'Bob ' + this.lastName; ``` - - Strings longer than 80 characters should be written across multiple lines using string concatenation. + - Strings longer than 80 characters should be avoided and likely call for using a template system or similar. + - If you have a good reason to have very long strings in code, they should be written across multiple lines using string concatenation. - Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40) ```javascript @@ -218,11 +176,8 @@ - When programatically building up a string, use Array#join instead of string concatenation. Mostly for IE: [jsPerf](http://jsperf.com/string-vs-array-concat/2). ```javascript - var items, - messages, - length, i; - messages = [{ + var messages = [{ state: 'success', message: 'This one worked.' },{ @@ -233,11 +188,12 @@ message: 'This one did not work.' }]; - length = messages.length; + var length = messages.length; // bad - function inbox(messages) { - items = '