Java 核心技术Java Web 核心技术javascript极简教程

禅与 JavaScript 编程艺术, Zen and The

2018-06-15  本文已影响38人  光剑书架上的书

禅与 JavaScript 编程艺术

Zen and The Art of JavaScript Programming

参考资料: Airbnb JavaScript Style Guide

目录

  1. 类型
  2. 引用
  3. 对象
  4. 数组
  5. 解构
  6. 字符串
  7. 函数
  8. 箭头函数
  9. 构造函数
  10. 模块
  11. 迭代器和生成器
  12. 属性
  13. 变量
  14. 提升
  15. 比较运算符和等号
  16. 代码块
  17. 注释
  18. 空白
  19. 逗号
  20. 分号
  21. 类型转换
  22. 命名规则
  23. 存取器
  24. 事件
  25. jQuery
  26. ECMAScript 5 兼容性
  27. ECMAScript 6 编码规范
  28. 测试
  29. 性能
  30. 相关资源
  31. 使用情况
  32. 其他翻译
  33. JavaScript 编码规范说明
  34. 讨论 JavaScript
  35. 贡献者
  36. 许可协议

类型

Variable types

Computers are sophisticated and can make use of more complex variables than just numbers. This is where variable types come in. Variables come in several types and different languages support different types.

The most common types are:

Numbers
Float: a number, like 1.21323, 4, -33.5, 100004 or 0.123
Integer: a number like 1, 12, -33, 140 but not 1.233

String: a line of text like "boat", "elephant" or "damn, you are tall!"

Boolean: either true or false, but nothing else

Arrays: a collection of values like: 1,2,3,4,'I am bored now'

Objects: a representation of a more complex object

null: a variable that contains null contains no valid Number, String, Boolean, Array, or Object

undefined: the undefined value is obtained when you use an object property that does not exist, or a variable that has been declared, but has no value assigned to it.

JavaScript is a “loosely typed” language, which means that you don't have to explicitly declare what type of data the variables are. You just need to use the var keyword to indicate that you are declaring a variable, and the interpreter will work out what data type you are using from the context, and use of quotes.

引用

对象

数组

解构

Strings

函数

为什么?因为这样的写法让人感到很困惑。

var b = 1;
// bad
function count(a = b++) {
  console.log(a);
}
count();  // 1
count();  // 2
count(3); // 3
count();  // 3

箭头函数

构造器

模块

Iterators and Generators

为什么?因为它们现在还没法很好地编译到 ES5。 (译者注:目前(2016/03) Chrome 和 Node.js 的稳定版本都已支持 generators)

属性

变量

Hoisting

比较运算符和等号

代码块

注释

空白

逗号

分号

类型转换

命名规则

存取器

事件

jQuery

ECMAScript 5 兼容性

ECMAScript 6 规范

  1. 箭头函数
  2. 对象方法简写
  3. 对象属性简写
  4. 对象中的可计算属性
  5. 模板字符串
  6. 解构
  7. 默认参数
  8. Rest
  9. 数组 Spreads
  10. Let 及 Const
  11. 迭代器和生成器
  12. 模块

测试

性能

相关资源(英文)

了解 ES6

看看这个

工具

其他风格指南

其他风格

拓展阅读

书籍

博客

播客

使用情况

下列组织应用这份风格指南。

翻译

这份风格指南也有其他语言的译本:

JavaScript 编码规范说明

讨论 JavaScript

贡献者

许可协议

(The MIT License)

Copyright (c) 2014 Airbnb

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

修订

我们鼓励您派生本指南和更改规则以适应您的团队需求。您可以在下方列出对本风格指南的修改,以便定期更新本指南而无需处理合并冲突。

上一篇下一篇

猜你喜欢

热点阅读