Skip to content

Commit 74f2097

Browse files
committed
Merge pull request #2 from airbnb/master
updating repo
2 parents c320da1 + 95b6b5f commit 74f2097

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

‎README.md‎

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,40 @@
8383
var item ={};
8484
```
8585

86-
- Don't use [reserved words](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Reserved_Words) as keys.
86+
- Don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work inIE8. [More info](https://github.com/airbnb/javascript/issues/61)
8787

8888
```javascript
8989
// bad
9090
var superman ={
91-
class: 'superhero',
9291
default:{clark: 'kent'},
9392
private: true
9493
};
9594
9695
// good
9796
var superman ={
98-
klass: 'superhero',
9997
defaults:{clark: 'kent'},
10098
hidden: true
10199
};
102100
```
101+
102+
- Use readable synonyms in place of reserved words.
103+
104+
```javascript
105+
// bad
106+
var superman ={
107+
class: 'alien'
108+
};
109+
110+
// bad
111+
var superman ={
112+
klass: 'alien'
113+
};
114+
115+
// good
116+
var superman ={
117+
type: 'alien'
118+
};
119+
```
103120
**[[⬆]](#TOC)**
104121

105122
## <a name='arrays'>Arrays</a>
@@ -203,7 +220,8 @@
203220
```javascript
204221
var items,
205222
messages,
206-
length, i;
223+
length,
224+
i;
207225
208226
messages = [{
209227
state: 'success',
@@ -503,18 +521,17 @@
503521
varnamed=functionsuperPower(){
504522
console.log('Flying');
505523
};
524+
}
506525

526+
// the same is true when the function name
527+
// is the same as the variable name.
528+
functionexample(){
529+
console.log(named); // => undefined
507530

508-
// the same is true when the function name
509-
// is the same as the variable name.
510-
functionexample(){
511-
console.log(named); // => undefined
512-
513-
named(); // => TypeError named is not a function
531+
named(); // => TypeError named is not a function
514532

515-
varnamed=functionnamed(){
516-
console.log('named');
517-
};
533+
varnamed=functionnamed(){
534+
console.log('named');
518535
}
519536
}
520537
```
@@ -648,7 +665,7 @@
648665
}
649666
```
650667
651-
- Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an emptyline before the comment.
668+
- Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment.
652669

653670
```javascript
654671
// bad
@@ -914,7 +931,6 @@
914931
```
915932
916933
- Use `parseInt` for Numbers and always with a radix for type casting.
917-
- If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing.
918934
919935
```javascript
920936
var inputValue = '4';
@@ -936,7 +952,11 @@
936952
937953
// good
938954
var val = parseInt(inputValue, 10);
955+
```
956+
957+
- If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing.
939958

959+
```javascript
940960
// good
941961
/**
942962
* parseInt was the reason my code was slow.
@@ -1250,7 +1270,7 @@
12501270
12511271
## <a name='modules'>Modules</a>
12521272
1253-
- The module should start with a `!`. This ensures that if a malformed module forgets to include a final semicolon there aren't errors in production when the scripts get concatenated.
1273+
- The module should start with a `!`. This ensures that if a malformed module forgets to include a final semicolon there aren't errors in production when the scripts get concatenated. [Explanation](https://github.com/airbnb/javascript/issues/44#issuecomment-13063933)
12541274
- The file should be named with camelCase, live in a folder with the same name, and match the name of the single export.
12551275
- Add a method called noConflict() that sets the exported module to the previous version and returns this one.
12561276
- Always declare `'use strict'` at the top of the module.
@@ -1323,7 +1343,7 @@
13231343

13241344
```javascript
13251345
// bad
1326-
$('.sidebar', 'ul').hide();
1346+
$('ul', '.sidebar').hide();
13271347
13281348
// bad
13291349
$('.sidebar').find('ul').hide();
@@ -1334,11 +1354,8 @@
13341354
// good
13351355
$('.sidebar > ul').hide();
13361356
1337-
// good (slower)
1357+
// good
13381358
$sidebar.find('ul');
1339-
1340-
// good (faster)
1341-
$($sidebar[0]).find('ul');
13421359
```
13431360

13441361
**[[⬆]](#TOC)**
@@ -1399,6 +1416,7 @@
13991416
**Further Reading**
14001417

14011418
- [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll
1419+
- [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer
14021420

14031421
**Books**
14041422

@@ -1410,6 +1428,10 @@
14101428
- [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw
14111429
- [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig
14121430
- [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch
1431+
- [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault
1432+
- [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg
1433+
- [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy
1434+
- [JSBooks](http://jsbooks.revolunet.com/)
14131435

14141436
**Blogs**
14151437

@@ -1437,6 +1459,7 @@
14371459
- **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)
14381460
- **GeneralElectric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
14391461
- **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)
1462+
- **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
14401463
- **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript)
14411464
- **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
14421465
- **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)
@@ -1456,6 +1479,7 @@
14561479
- :jp: **Japanese**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide)
14571480
- :br: **Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)
14581481
- :cn: **Chinese**: [adamlu/javascript-style-guide](https://github.com/adamlu/javascript-style-guide)
1482+
- :es: **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)
14591483
14601484
## <a name='guide-guide'>The JavaScript Style Guide Guide</a>
14611485

0 commit comments

Comments
(0)