From 0e20d831833c9d8f68c683cf7cd5ef05d18497b5 Mon Sep 17 00:00:00 2001 From: Ben Zhao Date: 2015年12月10日 12:26:39 +0800 Subject: [PATCH 1/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4509003ce1..92025685b8 100644 --- a/README.md +++ b/README.md @@ -861,7 +861,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl const superPower = new SuperPower(); ``` - - [13.2](#13.2) 使用 `var` 声明每一个变量。 + - [13.2](#13.2) 使用 `const` 声明每一个变量。 > 为什么?增加新变量将变的更加容易,而且你永远不用再担心调换错 `;` 跟 `,`。 From 768c3e43ce85ff10224a8326969284baa2d52472 Mon Sep 17 00:00:00 2001 From: zousandian Date: 2016年3月10日 17:45:26 +0800 Subject: [PATCH 2/8] =?UTF-8?q?typo=20=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 时间 -> 事件 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92025685b8..7bbc1ccca2 100644 --- a/README.md +++ b/README.md @@ -1806,7 +1806,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl ## 事件 - - [24.1](#24.1) 当给时间附加数据时(无论是 DOM 事件还是私有事件),传入一个哈希而不是原始值。这样可以让后面的贡献者增加更多数据到事件数据而无需找出并更新事件的每一个处理器。例如,不好的写法: + - [24.1](#24.1) 当给事件附加数据时(无论是 DOM 事件还是私有事件),传入一个哈希而不是原始值。这样可以让后面的贡献者增加更多数据到事件数据而无需找出并更新事件的每一个处理器。例如,不好的写法: ```javascript // bad From 2768a3ebf368c2eb9446b8ff8d8ba777710a61c7 Mon Sep 17 00:00:00 2001 From: yuche Date: 2016年3月29日 15:23:54 +0800 Subject: [PATCH 3/8] fixed --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7bbc1ccca2..2912a8ddeb 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl ## 引用 - - [2.1](#2.1) 对所有的引用使用 `const` ;避免使用 `var`。 + - [2.1](#2.1) 对所有的引用使用 `const` ;不要使用 `var`。 > 为什么?这能确保你无法对引用重新赋值,也不会导致出现 bug 或难以理解。 @@ -809,7 +809,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [11.2](#11.2) 现在还不要使用 generators。 -> 为什么?因为它们现在还没法很好地编译到 ES5。 +> 为什么?因为它们现在还没法很好地编译到 ES5。 (译者注:目前(2016/03) Chrome 和 Node.js 的稳定版本都已支持 generators) **[⬆ 返回目录](#table-of-contents)** From 12315cf7557846d064b8d70e7e1a2700ea38bb84 Mon Sep 17 00:00:00 2001 From: Gallen Date: 2016年4月25日 12:48:59 +0800 Subject: [PATCH 4/8] fixed --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2912a8ddeb..45ed0fb9df 100644 --- a/README.md +++ b/README.md @@ -1667,15 +1667,16 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl }); ``` - - [22.4](#22.4) 使用下划线 `_` 开头命名私有属性。 + - [22.4](#22.4) 不要使用下划线 `_` 结尾或开头来命名属性和方法。 ```javascript // bad this.__firstName__ = 'Panda'; this.firstName_ = 'Panda'; + this._firstName = 'Panda'; // good - this._firstName = 'Panda'; + this.firstName = 'Panda'; ``` - [22.5](#22.5) 别保存 `this` 的引用。使用箭头函数或 Function#bind。 From 6950afcff0f48c58c6c41f64e64ae92eef95903e Mon Sep 17 00:00:00 2001 From: shery <382254994@qq.com> Date: 2017年2月21日 11:11:01 +0800 Subject: [PATCH 5/8] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 翻译错误 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2912a8ddeb..daef32fbf3 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl console.log(foo, bar); // => 1, 9 ``` - - [1.2](#1.2) **复制类型**: 通过引用的方式存取复杂类型。 + - [1.2](#1.2) **复杂类型**: 通过引用的方式存取复杂类型。 + `对象` + `数组` From 77431efc261032264e48ead87d519417700ace0b Mon Sep 17 00:00:00 2001 From: shery15 <382254994@qq.com> Date: 2017年2月23日 17:17:12 +0800 Subject: [PATCH 6/8] fix typesetting --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index daef32fbf3..6f39556323 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl 1. [License](#license) -## 类型 +## 类型 - [1.1](#1.1) **基本类型**: 直接存取基本类型。 @@ -67,7 +67,8 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl console.log(foo, bar); // => 1, 9 ``` - - [1.2](#1.2) **复杂类型**: 通过引用的方式存取复杂类型。 + + - [1.2](#1.2) **复杂类型**: 通过引用的方式存取复杂类型。 + `对象` + `数组` @@ -911,7 +912,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [13.4](#13.4) 在你需要的地方给变量赋值,但请把它们放在一个合理的位置。 > 为什么?`let` 和 `const` 是块级作用域而不是函数作用域。 - + ```javascript // good function() { @@ -963,7 +964,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [14.1](#14.1) `var` 声明会被提升至该作用域的顶部,但它们赋值不会提升。`let` 和 `const` 被赋予了一种称为「[暂时性死区(Temporal Dead Zones, TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let)」的概念。这对于了解为什么 [type of 不再安全](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15)相当重要。 ```javascript - // 我们知道这样运行不了 + // 我们知道这样运行不了 // (假设 notDefined 不是全局变量) function example() { console.log(notDefined); // => throws a ReferenceError From dca72e0708f70b9a86037c9150db902ad6e9e351 Mon Sep 17 00:00:00 2001 From: YFdyh000 Date: 2017年7月10日 06:22:33 +0800 Subject: [PATCH 7/8] Update README.md --- README.md | 160 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index df01acc7d3..2cd0c82fd2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) - # Airbnb JavaScript Style Guide() { **用更合理的方式写 JavaScript** +[![Downloads](https://img.shields.io/npm/dm/eslint-config-airbnb.svg)](https://www.npmjs.com/package/eslint-config-airbnb) +[![Downloads](https://img.shields.io/npm/dm/eslint-config-airbnb-base.svg)](https://www.npmjs.com/package/eslint-config-airbnb-base) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-style-guide/blob/master/es5/README.md),[版本二](https://github.com/adamlu/javascript-style-guide)。 翻译自 [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) 。 @@ -21,11 +23,11 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl 1. [箭头函数](#arrow-functions) 1. [构造函数](#constructors) 1. [模块](#modules) - 1. [Iterators & Generators ](#iterators-and-generators) + 1. [迭代器和生成器](#iterators-and-generators) 1. [属性](#properties) 1. [变量](#variables) 1. [提升](#hoisting) - 1. [比较运算符 & 等号](#comparison-operators--equality) + 1. [比较运算符和等号](#comparison-operators--equality) 1. [代码块](#blocks) 1. [注释](#comments) 1. [空白](#whitespace) @@ -40,13 +42,13 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl 1. [ECMAScript 6 编码规范](#ecmascript-6-styles) 1. [测试](#testing) 1. [性能](#performance) - 1. [资源](#resources) - 1. [使用人群](#in-the-wild) - 1. [翻译](#translation) + 1. [相关资源](#resources) + 1. [使用情况](#in-the-wild) + 1. [其他翻译](#translation) 1. [JavaScript 编码规范说明](#the-javascript-style-guide-guide) - 1. [一起来讨论 JavaScript](#chat-with-us-about-javascript) - 1. [Contributors](#contributors) - 1. [License](#license) + 1. [讨论 JavaScript](#chat-with-us-about-javascript) + 1. [贡献者](#contributors) + 1. [许可协议](#license) ## 类型 @@ -1053,7 +1055,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl **[⬆ 返回目录](#table-of-contents)** -## 比较运算符 & 等号 +## 比较运算符和等号 - [15.1](#15.1) 优先使用 `===` 和 `!==` 而不是 `==` 和 `!=`. - [15.2](#15.2) 条件表达式例如 `if` 语句通过抽象方法 `ToBoolean` 强制计算它们的表达式并且总是遵守下面的规则: @@ -1901,28 +1903,28 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl ## ECMAScript 5 兼容性 - - [26.1](#26.1) 参考 [Kangax](https://twitter.com/kangax/) 的 ES5 [兼容性](http://kangax.github.com/es5-compat-table/). + - [26.1](#26.1) 参考 [Kangax](https://twitter.com/kangax/) 的 ES5 [兼容性](http://kangax.github.com/es5-compat-table/)。 **[⬆ 返回目录](#table-of-contents)** ## ECMAScript 6 规范 - - [27.1](#27.1) 以下是链接到 ES6 的各个特性的列表。 + - [27.1](#27.1) 以下是链接到 ES6 各个特性的列表。 -1. [Arrow Functions](#arrow-functions) -1. [Classes](#constructors) -1. [Object Shorthand](#es6-object-shorthand) -1. [Object Concise](#es6-object-concise) -1. [Object Computed Properties](#es6-computed-properties) -1. [Template Strings](#es6-template-literals) -1. [Destructuring](#destructuring) -1. [Default Parameters](#es6-default-parameters) +1. [箭头函数](#arrow-functions) +1. [类](#constructors) +1. [对象方法简写](#es6-object-shorthand) +1. [对象属性简写](#es6-object-concise) +1. [对象中的可计算属性](#es6-computed-properties) +1. [模板字符串](#es6-template-literals) +1. [解构](#destructuring) +1. [默认参数](#es6-default-parameters) 1. [Rest](#es6-rest) -1. [Array Spreads](#es6-array-spreads) -1. [Let and Const](#references) -1. [Iterators and Generators](#iterators-and-generators) -1. [Modules](#modules) +1. [数组 Spreads](#es6-array-spreads) +1. [Let 及 Const](#references) +1. [迭代器和生成器](#iterators-and-generators) +1. [模块](#modules) **[⬆ 返回目录](#table-of-contents)** @@ -1949,45 +1951,46 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13) - [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text) - [Long String Concatenation](http://jsperf.com/ya-string-concat) - - Loading... + - [Are Javascript functions like `map()`, `reduce()`, and `filter()` optimized for traversing arrays?](https://www.quora.com/JavaScript-programming-language-Are-Javascript-functions-like-map-reduce-and-filter-already-optimized-for-traversing-array/answer/Quildreen-Motta) + - 等等... **[⬆ 返回目录](#table-of-contents)** -## 资源 +## 相关资源(英文) -**Learning ES6** +**了解 ES6** - - [Draft ECMA 2015 (ES6) Spec](https://people.mozilla.org/~jorendorff/es6-draft.html) + - [ECMA 2015 (ES6) 规范草案](https://people.mozilla.org/~jorendorff/es6-draft.html) - [ExploringJS](http://exploringjs.com/) - - [ES6 Compatibility Table](https://kangax.github.io/compat-table/es6/) - - [Comprehensive Overview of ES6 Features](http://es6-features.org/) + - [ES6 兼容性表](https://kangax.github.io/compat-table/es6/) + - [ES6 特性全面概况](http://es6-features.org/) -**Read This** +**看看这个** - [Annotated ECMAScript 5.1](http://es5.github.com/) -**Tools** +**工具** - - Code Style Linters + - 代码风格检查器(Lint) + [ESlint](http://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc) + [JSHint](http://www.jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc) + [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json) -**Other Styleguides** +**其他风格指南** - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml) - [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines) - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/) -**Other Styles** +**其他风格** - [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - Ross Allen - [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun - [Multiple var statements in JavaScript, not superfluous](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman -**Further Reading** +**拓展阅读** - [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll - [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer @@ -1995,7 +1998,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [ES6 Features](https://github.com/lukehoban/es6features) - Luke Hoban - [Frontend Guidelines](https://github.com/bendc/frontend-guidelines) - Benjamin De Cock -**Books** +**书籍** - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov @@ -2013,7 +2016,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman - [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke -**Blogs** +**博客** - [DailyJS](http://dailyjs.com/) - [JavaScript Weekly](http://javascriptweekly.com/) @@ -2027,7 +2030,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [Dustin Diaz](http://dustindiaz.com/) - [nettuts](http://net.tutsplus.com/?s=javascript) -**Podcasts** +**播客** - [JavaScript Jabber](http://devchat.tv/js-jabber/) @@ -2035,56 +2038,92 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl **[⬆ 返回目录](#table-of-contents)** -## 使用人群 +## 使用情况 - This is a list of organizations that are using this style guide. Send us a pull request or open an issue and we'll add you to the list. + 下列组织应用这份风格指南。 + - **3blades**: [3Blades/javascript](https://github.com/3blades/javascript) + - **4Catalyzer**: [4Catalyzer/javascript](https://github.com/4Catalyzer/javascript) - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript) - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript) - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript) - - **American Insitutes for Research**: [AIRAST/javascript](https://github.com/AIRAST/javascript) + - **AltSchool**: [AltSchool/javascript](https://github.com/AltSchool/javascript) - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript) + - **Ascribe**: [ascribe/javascript](https://github.com/ascribe/javascript) - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript) + - **Avant**: [avantcredit/javascript](https://github.com/avantcredit/javascript) + - **Axept**: [axept/javascript](https://github.com/axept/javascript) + - **BashPros**: [BashPros/javascript](https://github.com/BashPros/javascript) - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) + - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/) + - **Bonhomme**: [bonhommeparis/javascript](https://github.com/bonhommeparis/javascript) + - **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript) + - **CaseNine**: [CaseNine/javascript](https://github.com/CaseNine/javascript) + - **Chartboost**: [ChartBoost/javascript-style-guide](https://github.com/ChartBoost/javascript-style-guide) + - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide) - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) + - **DoSomething**: [DoSomething/eslint-config](https://github.com/DoSomething/eslint-config) - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) + - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript) - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide) + - **Evolution Gaming**: [evolution-gaming/javascript](https://github.com/evolution-gaming/javascript) + - **EvozonJs**: [evozonjs/javascript](https://github.com/evozonjs/javascript) - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript) - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md) - **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide) - **Gawker Media**: [gawkermedia/javascript](https://github.com/gawkermedia/javascript) - - **GeneralElectric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript) + - **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript) + - **Generation Tux**: [GenerationTux/javascript](https://github.com/generationtux/styleguide) - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style) - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript) - - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript) - - **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide) - - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript) + - **Honey**: [honeyscience/javascript](https://github.com/honeyscience/javascript) + - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide) + - **Huballin**: [huballin/javascript](https://github.com/huballin/javascript) + - **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript) + - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md) + - **InterCity Group**: [intercitygroup/javascript-style-guide](https://github.com/intercitygroup/javascript-style-guide) - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions) + - **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md) - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript) - - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/javascript) + - **KickorStick**: [kickorstick/javascript](https://github.com/kickorstick/javascript) + - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide) + - **Lonely Planet**: [lonelyplanet/javascript](https://github.com/lonelyplanet/javascript) + - **M2GEN**: [M2GEN/javascript](https://github.com/M2GEN/javascript) - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript) - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript) + - **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript) - **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript) - **Money Advice Service**: [moneyadviceservice/javascript](https://github.com/moneyadviceservice/javascript) - **Muber**: [muber/javascript](https://github.com/muber/javascript) - **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript) - - **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript) - **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript) + - **Nulogy**: [nulogy/javascript](https://github.com/nulogy/javascript) + - **Orange Hill Development**: [orangehill/javascript](https://github.com/orangehill/javascript) - **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript) + - **OutBoxSoft**: [OutBoxSoft/javascript](https://github.com/OutBoxSoft/javascript) - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript) - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide) - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript) - - **REI**: [reidev/js-style-guide](https://github.com/reidev/js-style-guide) + - **React**: [facebook.github.io/react/contributing/how-to-contribute.html#style-guide](https://facebook.github.io/react/contributing/how-to-contribute.html#style-guide) + - **REI**: [reidev/js-style-guide](https://github.com/rei/code-style-guides/blob/master/docs/javascript.md) - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide) - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide) - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/javascript) + - **Sourcetoad**: [sourcetoad/javascript](https://github.com/sourcetoad/javascript) + - **Springload**: [springload/javascript](https://github.com/springload/javascript) + - **StratoDem Analytics**: [stratodem/javascript](https://github.com/stratodem/javascript) + - **SteelKiwi Development**: [steelkiwi/javascript](https://github.com/steelkiwi/javascript) + - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript) + - **SwoopApp**: [swoopapp/javascript](https://github.com/swoopapp/javascript) + - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide) + - **Syzygy Warsaw**: [syzygypl/javascript](https://github.com/syzygypl/javascript) - **Target**: [target/javascript](https://github.com/target/javascript) - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) + - **The Nerdery**: [thenerdery/javascript-standards](https://github.com/thenerdery/javascript-standards) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) - - **Userify**: [userify/javascript](https://github.com/userify/javascript) - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide) + - **WeBox Studio**: [weboxstudio/javascript](https://github.com/weboxstudio/javascript) - **Weggo**: [Weggo/javascript](https://github.com/Weggo/javascript) - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript) - **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript) @@ -2094,7 +2133,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl ## 翻译 - This style guide is also available in other languages: + 这份风格指南也有其他语言的译本: - ![br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide) - ![bg](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Bulgaria.png) **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript) @@ -2117,16 +2156,17 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide) -## 一起来讨论 JavaScript +## 讨论 JavaScript - - Find us on [gitter](https://gitter.im/airbnb/javascript). + - 欢迎到 [gitter](https://gitter.im/airbnb/javascript) 与我们聊天(英文)。 -## Contributors +## 贡献者 - - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors) + - [查看原始项目贡献者](https://github.com/airbnb/javascript/graphs/contributors) + - [查看简中翻译贡献者](https://github.com/yuche/javascript/graphs/contributors) -## License +## 许可协议 (The MIT License) @@ -2153,4 +2193,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **[⬆ 返回目录](#table-of-contents)** +## 修订 + +我们鼓励您派生本指南和更改规则以适应您的团队需求。您可以在下方列出对本风格指南的修改,以便定期更新本指南而无需处理合并冲突。 + # }; From 9cd4082b81b043a317d99b30aa5fefc89f7ee01f Mon Sep 17 00:00:00 2001 From: Liu Date: 2018年1月30日 15:42:25 +0800 Subject: [PATCH 8/8] Correct the format of the code block --- README.md | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 2cd0c82fd2..9e4700d55a 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [2.1](#2.1) 对所有的引用使用 `const` ;不要使用 `var`。 -> 为什么?这能确保你无法对引用重新赋值,也不会导致出现 bug 或难以理解。 +> 为什么?这能确保你无法对引用重新赋值,也不会导致出现 bug 或难以理解。 ```javascript // bad @@ -106,7 +106,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [2.2](#2.2) 如果你一定需要可变动的引用,使用 `let` 代替 `var`。 -> 为什么?因为 `let` 是块级作用域,而 `var` 是函数作用域。 +> 为什么?因为 `let` 是块级作用域,而 `var` 是函数作用域。 ```javascript // bad @@ -187,7 +187,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [3.4](#3.4) 创建有动态属性名的对象时,使用可被计算的属性名称。 -> 为什么?因为这样可以让你在一个地方定义所有的对象属性。 +> 为什么?因为这样可以让你在一个地方定义所有的对象属性。 ```javascript function getKey(k) { @@ -235,7 +235,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [3.6](#3.6) 使用对象属性值的简写。 -> 为什么?因为这样更短更有描述性。 +> 为什么?因为这样更短更有描述性。 ```javascript const lukeSkywalker = 'Luke Skywalker'; @@ -253,7 +253,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [3.7](#3.7) 在对象属性声明前把简写的属性分组。 -> 为什么?因为这样能清楚地看出哪些属性使用了简写。 +> 为什么?因为这样能清楚地看出哪些属性使用了简写。 ```javascript const anakinSkywalker = 'Anakin Skywalker'; @@ -338,7 +338,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [5.1](#5.1) 使用解构存取和使用多属性对象。 -> 为什么?因为解构能减少临时引用属性。 +> 为什么?因为解构能减少临时引用属性。 ```javascript // bad @@ -375,7 +375,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl ``` - [5.3](#5.3) 需要回传多个值时,使用对象解构,而不是数组解构。 -> 为什么?增加属性或者改变排序不会改变调用时的位置。 +> 为什么?增加属性或者改变排序不会改变调用时的位置。 ```javascript // bad @@ -435,7 +435,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [6.4](#6.4) 程序化生成字符串时,使用模板字符串代替字符串连接。 -> 为什么?模板字符串更为简洁,更具可读性。 +> 为什么?模板字符串更为简洁,更具可读性。 ```javascript // bad @@ -461,7 +461,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [7.1](#7.1) 使用函数声明代替函数表达式。 -> 为什么?因为函数声明是可命名的,所以他们在调用栈中更容易被识别。此外,函数声明会把整个函数提升(hoisted),而函数表达式只会把函数的引用变量名提升。这条规则使得[箭头函数](#arrow-functions)可以取代函数表达式。 +> 为什么?因为函数声明是可命名的,所以他们在调用栈中更容易被识别。此外,函数声明会把整个函数提升(hoisted),而函数表达式只会把函数的引用变量名提升。这条规则使得[箭头函数](#arrow-functions)可以取代函数表达式。 ```javascript // bad @@ -519,7 +519,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [7.6](#7.6) 不要使用 `arguments`。可以选择 rest 语法 `...` 替代。 -> 为什么?使用 `...` 能明确你要传入的参数。另外 rest 参数是一个真正的数组,而 `arguments` 是一个类数组。 +> 为什么?使用 `...` 能明确你要传入的参数。另外 rest 参数是一个真正的数组,而 `arguments` 是一个类数组。 ```javascript // bad @@ -586,27 +586,29 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [8.1](#8.1) 当你必须使用函数表达式(或传递一个匿名函数)时,使用箭头函数符号。 -> 为什么?因为箭头函数创造了新的一个 `this` 执行环境(译注:参考 [Arrow functions - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) 和 [ES6 arrow functions, syntax and lexical scoping](http://toddmotto.com/es6-arrow-functions-syntaxes-and-lexical-scoping/)),通常情况下都能满足你的需求,而且这样的写法更为简洁。 +> 为什么?因为箭头函数创造了新的一个 `this` 执行环境(译注:参考 [Arrow functions - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) 和 [ES6 arrow functions, syntax and lexical scoping](http://toddmotto.com/es6-arrow-functions-syntaxes-and-lexical-scoping/)),通常情况下都能满足你的需求,而且这样的写法更为简洁。 -> 为什么不?如果你有一个相当复杂的函数,你或许可以把逻辑部分转移到一个函数声明上。 +> 为什么不?如果你有一个相当复杂的函数,你或许可以把逻辑部分转移到一个函数声明上。 ```javascript // bad [1, 2, 3].map(function (x) { - return x * x; + const y = x + 1; + return x * y; }); // good [1, 2, 3].map((x) => { - return x * x; + const y = x + 1; + return x * y; }); ``` - [8.2](#8.2) 如果一个函数适合用一行写出并且只有一个参数,那就把花括号、圆括号和 `return` 都省略掉。如果不是,那就不要省略。 -> 为什么?语法糖。在链式调用中可读性很高。 +> 为什么?语法糖。在链式调用中可读性很高。 -> 为什么不?当你打算回传一个对象的时候。 +> 为什么不?当你打算回传一个对象的时候。 ```javascript // good @@ -625,7 +627,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [9.1](#9.1) 总是使用 `class`。避免直接操作 `prototype` 。 -> 为什么? 因为 `class` 语法更为简洁更易读。 +> 为什么? 因为 `class` 语法更为简洁更易读。 ```javascript // bad @@ -654,7 +656,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [9.2](#9.2) 使用 `extends` 继承。 -> 为什么?因为 `extends` 是一个内建的原型继承方法并且不会破坏 `instanceof`。 +> 为什么?因为 `extends` 是一个内建的原型继承方法并且不会破坏 `instanceof`。 ```javascript // bad @@ -737,7 +739,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [10.1](#10.1) 总是使用模组 (`import`/`export`) 而不是其他非标准模块系统。你可以编译为你喜欢的模块系统。 -> 为什么?模块就是未来,让我们开始迈向未来吧。 +> 为什么?模块就是未来,让我们开始迈向未来吧。 ```javascript // bad @@ -755,7 +757,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [10.2](#10.2) 不要使用通配符 import。 -> 为什么?这样能确保你只有一个默认 export。 +> 为什么?这样能确保你只有一个默认 export。 ```javascript // bad @@ -767,7 +769,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [10.3](#10.3) 不要从 import 中直接 export。 -> 为什么?虽然一行代码简洁明了,但让 import 和 export 各司其职让事情能保持一致。 +> 为什么?虽然一行代码简洁明了,但让 import 和 export 各司其职让事情能保持一致。 ```javascript // bad @@ -787,7 +789,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [11.1](#11.1) 不要使用 iterators。使用高阶函数例如 `map()` 和 `reduce()` 替代 `for-of`。 -> 为什么?这加强了我们不变的规则。处理纯函数的回调值更易读,这比它带来的副作用更重要。 +> 为什么?这加强了我们不变的规则。处理纯函数的回调值更易读,这比它带来的副作用更重要。 ```javascript const numbers = [1, 2, 3, 4, 5]; @@ -888,7 +890,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [13.3](#13.3) 将所有的 `const` 和 `let` 分组 -> 为什么?当你需要把已赋值变量赋值给未赋值变量时非常有用。 +> 为什么?当你需要把已赋值变量赋值给未赋值变量时非常有用。 ```javascript // bad @@ -913,7 +915,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [13.4](#13.4) 在你需要的地方给变量赋值,但请把它们放在一个合理的位置。 -> 为什么?`let` 和 `const` 是块级作用域而不是函数作用域。 +> 为什么?`let` 和 `const` 是块级作用域而不是函数作用域。 ```javascript // good @@ -1468,7 +1470,7 @@ ES5 的编码规范请查看[版本一](https://github.com/sivan/javascript-styl - [19.2](#19.2) 增加结尾的逗号: **需要**。 -> 为什么? 这会让 git diffs 更干净。另外,像 babel 这样的转译器会移除结尾多余的逗号,也就是说你不必担心老旧浏览器的[尾逗号问题](es5/README.md#commas)。 +> 为什么? 这会让 git diffs 更干净。另外,像 babel 这样的转译器会移除结尾多余的逗号,也就是说你不必担心老旧浏览器的[尾逗号问题](es5/README.md#commas)。 ```javascript // bad - git diff without trailing comma

AltStyle によって変換されたページ (->オリジナル) /