diff --git a/docs/async.md b/docs/async.md index 0852d35..09e1ba5 100644 --- a/docs/async.md +++ b/docs/async.md @@ -708,7 +708,7 @@ async function logInOrder(urls) { 这里隐含着一个规定,`next`方法必须是同步的,只要调用就必须立刻返回值。也就是说,一旦执行`next`方法,就必须同步地得到`value`和`done`这两个属性。如果遍历指针正好指向同步操作,当然没有问题,但对于异步操作,就不太合适了。目前的解决方法是,Generator 函数里面的异步操作,返回一个 Thunk 函数或者 Promise 对象,即`value`属性是一个 Thunk 函数或者 Promise 对象,等待以后返回真正的值,而`done`属性则还是同步产生的。 -ES2018 [引入](https://github.com/tc39/proposal-async-iteration)了”异步遍历器“(Async Iterator),为异步操作提供原生的遍历器接口,即`value`和`done`这两个属性都是异步产生。 +ES2018 [引入](https://github.com/tc39/proposal-async-iteration)了“异步遍历器”(Async Iterator),为异步操作提供原生的遍历器接口,即`value`和`done`这两个属性都是异步产生。 ### 异步遍历的接口 diff --git a/docs/function.md b/docs/function.md index 0384b5a..cdd4978 100644 --- a/docs/function.md +++ b/docs/function.md @@ -1356,4 +1356,3 @@ clownsEverywhere( ``` 这样的规定也使得,函数参数与数组和对象的尾逗号规则,保持一致了。 - diff --git a/docs/generator-async.md b/docs/generator-async.md index 53966a3..0c96df8 100644 --- a/docs/generator-async.md +++ b/docs/generator-async.md @@ -1,6 +1,6 @@ # Generator 函数的异步应用 -异步编程对 JavaScript 语言太重要。Javascript 语言的执行环境是“单线程”的,如果没有异步编程,根本没法用,非卡死不可。本章主要介绍 Generator 函数如何完成异步操作。 +异步编程对 JavaScript 语言太重要。JavaScript 语言的执行环境是“单线程”的,如果没有异步编程,根本没法用,非卡死不可。本章主要介绍 Generator 函数如何完成异步操作。 ## 传统方法 @@ -756,7 +756,7 @@ function* somethingAsync(x) { Node 提供 Stream 模式读写数据,特点是一次只处理数据的一部分,数据分成一块块依次处理,就好像“数据流”一样。这对于处理大规模数据非常有利。Stream 模式使用 EventEmitter API,会释放三个事件。 - `data`事件:下一块数据块已经准备好了。 -- `end`事件:整个“数据流”处理“完了。 +- `end`事件:整个“数据流”处理完了。 - `error`事件:发生错误。 使用`Promise.race()`函数,可以判断这三个事件之中哪一个最先发生,只有当`data`事件最先发生时,才进入下一个数据块的处理。从而,我们可以通过一个`while`循环,完成所有数据的读取。 diff --git a/docs/intro.md b/docs/intro.md index d68fd0b..65d1d6f 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -10,7 +10,7 @@ ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准, 该标准从一开始就是针对 JavaScript 语言制定的,但是之所以不叫 JavaScript,有两个原因。一是商标,Java 是 Sun 公司的商标,根据授权协议,只有 Netscape 公司可以合法地使用 JavaScript 这个名字,且 JavaScript 本身也已经被 Netscape 公司注册为商标。二是想体现这门语言的制定者是 ECMA,不是 Netscape,这样有利于保证这门语言的开放性和中立性。 -因此,ECMAScript 和 JavaScript 的关系是,前者是后者的规格,后者是前者的一种实现(另外的 ECMAScript 方言还有 Jscript 和 ActionScript)。日常场合,这两个词是可以互换的。 +因此,ECMAScript 和 JavaScript 的关系是,前者是后者的规格,后者是前者的一种实现(另外的 ECMAScript 方言还有 JScript 和 ActionScript)。日常场合,这两个词是可以互换的。 ## ES6 与 ECMAScript 2015 的关系 @@ -40,7 +40,7 @@ ES6 的第一个版本,就这样在 2015 年 6 月发布了,正式名称就 - Stage 3 - Candidate(候选人阶段) - Stage 4 - Finished(定案阶段) -一个提案只要能进入 Stage 2,就差不多肯定会包括在以后的正式标准里面。ECMAScript 当前的所有提案,可以在 TC39 的官方网站[Github.com/tc39/ecma262](https://github.com/tc39/ecma262)查看。 +一个提案只要能进入 Stage 2,就差不多肯定会包括在以后的正式标准里面。ECMAScript 当前的所有提案,可以在 TC39 的官方网站[GitHub.com/tc39/ecma262](https://github.com/tc39/ecma262)查看。 本书的写作目标之一,是跟踪 ECMAScript 语言的最新进展,介绍 5.1 版本以后所有的新语法。对于那些明确或很有希望,将要列入标准的新语法,都将予以介绍。 @@ -60,7 +60,7 @@ ES6 从开始制定到最后发布,整整用了 15 年。 2009 年 12 月,ECMAScript 5.0 版正式发布。Harmony 项目则一分为二,一些较为可行的设想定名为 JavaScript.next 继续开发,后来演变成 ECMAScript 6;一些不是很成熟的设想,则被视为 JavaScript.next.next,在更远的将来再考虑推出。TC39 委员会的总体考虑是,ES5 与 ES3 基本保持兼容,较大的语法修正和新功能加入,将由 JavaScript.next 完成。当时,JavaScript.next 指的是 ES6,第六版发布以后,就指 ES7。TC39 的判断是,ES5 会在 2013 年的年中成为 JavaScript 开发的主流标准,并在此后五年中一直保持这个位置。 -2011 年 6 月,ECMAscript 5.1 版发布,并且成为 ISO 国际标准(ISO/IEC 16262:2011)。 +2011 年 6 月,ECMAScript 5.1 版发布,并且成为 ISO 国际标准(ISO/IEC 16262:2011)。 2013 年 3 月,ECMAScript 6 草案冻结,不再添加新功能。新的功能设想将被放到 ECMAScript 7。 @@ -89,7 +89,7 @@ $ npm install -g es-checker $ es-checker ========================================= -Passes 24 feature Dectations +Passes 24 feature Detections Your runtime supports 57% of ECMAScript 6 ========================================= ``` diff --git a/docs/let.md b/docs/let.md index 0d0069b..d27d5ac 100644 --- a/docs/let.md +++ b/docs/let.md @@ -75,7 +75,7 @@ for (let i = 0; i < 3; i++) { ### 不存在变量提升 -`var`命令会发生”变量提升“现象,即变量可以在声明之前使用,值为`undefined`。这种现象多多少少是有些奇怪的,按照一般的逻辑,变量应该在声明语句之后才可以使用。 +`var`命令会发生“变量提升”现象,即变量可以在声明之前使用,值为`undefined`。这种现象多多少少是有些奇怪的,按照一般的逻辑,变量应该在声明语句之后才可以使用。 为了纠正这种现象,`let`命令改变了语法行为,它所声明的变量一定要在声明后使用,否则报错。 @@ -153,7 +153,7 @@ function bar(x = y, y = 2) { bar(); // 报错 ``` -上面代码中,调用`bar`函数之所以报错(某些实现可能不报错),是因为参数`x`默认值等于另一个参数`y`,而此时`y`还没有声明,属于”死区“。如果`y`的默认值是`x`,就不会报错,因为此时`x`已经声明了。 +上面代码中,调用`bar`函数之所以报错(某些实现可能不报错),是因为参数`x`默认值等于另一个参数`y`,而此时`y`还没有声明,属于“死区”。如果`y`的默认值是`x`,就不会报错,因为此时`x`已经声明了。 ```javascript function bar(x = 2, y = x) { diff --git a/docs/object-methods.md b/docs/object-methods.md index 4d5baf2..d6f133a 100644 --- a/docs/object-methods.md +++ b/docs/object-methods.md @@ -831,4 +831,3 @@ Object.fromEntries(map) Object.fromEntries(new URLSearchParams('foo=bar&baz=qux')) // { foo: "bar", baz: "qux" } ``` - diff --git a/docs/object.md b/docs/object.md index 7277f20..049032d 100644 --- a/docs/object.md +++ b/docs/object.md @@ -317,7 +317,7 @@ Object.getOwnPropertyDescriptor(obj, 'foo') // } ``` -描述对象的`enumerable`属性,称为”可枚举性“,如果该属性为`false`,就表示某些操作会忽略当前属性。 +描述对象的`enumerable`属性,称为“可枚举性”,如果该属性为`false`,就表示某些操作会忽略当前属性。 目前,有四个操作会忽略`enumerable`为`false`的属性。 diff --git a/docs/promise.md b/docs/promise.md index 94638be..bda0dce 100644 --- a/docs/promise.md +++ b/docs/promise.md @@ -613,10 +613,10 @@ Promise.all([ booksPromise, userPromise ]) -.then(([books, user]) => pickTopRecommentations(books, user)); +.then(([books, user]) => pickTopRecommendations(books, user)); ``` -上面代码中,`booksPromise`和`userPromise`是两个异步操作,只有等到它们的结果都返回了,才会触发`pickTopRecommentations`这个回调函数。 +上面代码中,`booksPromise`和`userPromise`是两个异步操作,只有等到它们的结果都返回了,才会触发`pickTopRecommendations`这个回调函数。 注意,如果作为参数的 Promise 实例,自己定义了`catch`方法,那么它一旦被`rejected`,并不会触发`Promise.all()`的`catch`方法。 diff --git a/docs/proposals.md b/docs/proposals.md index 522b0f6..d6c2759 100644 --- a/docs/proposals.md +++ b/docs/proposals.md @@ -787,4 +787,3 @@ Math.signbit(-0) //true - 如果参数是`-0`,返回`true` - 如果参数是负值,返回`true` - 其他情况返回`false` - diff --git a/docs/reference.md b/docs/reference.md index 6620090..a2a989f 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -7,7 +7,7 @@ - [ECMAScript® 2017 Language Specification](https://tc39.github.io/ecma262/):ECMAScript 2017 规格(草案) - [ECMAScript Current Proposals](https://github.com/tc39/ecma262): ECMAScript 当前的所有提案 - [ECMAScript Active Proposals](https://github.com/tc39/proposals): 已经进入正式流程的提案 -- [ECMAscript proposals](https://github.com/hemanth/es-next):从阶段 0 到阶段 4 的所有提案列表 +- [ECMAScript proposals](https://github.com/hemanth/es-next):从阶段 0 到阶段 4 的所有提案列表 - [TC39 meeting agendas](https://github.com/tc39/agendas): TC39 委员会历年的会议记录 - [ECMAScript Daily](https://ecmascript-daily.github.io/): TC39 委员会的动态 - [The TC39 Process](https://tc39.github.io/process-document/): 提案进入正式规格的流程 @@ -33,7 +33,7 @@ - Guillermo Rauch, [ECMAScript 6](http://rauchg.com/2015/ecmascript-6/) - Benjamin De Cock, [Frontend Guidelines](https://github.com/bendc/frontend-guidelines): ES6 最佳实践 - Jani Hartikainen, [ES6: What are the benefits of the new features in practice?](http://codeutopia.net/blog/2015/01/06/es6-what-are-the-benefits-of-the-new-features-in-practice/) -- kangax, [Javascript quiz. ES6 edition](http://perfectionkills.com/javascript-quiz-es6/): ES6 小测试 +- kangax, [JavaScript quiz. ES6 edition](http://perfectionkills.com/javascript-quiz-es6/): ES6 小测试 - Jeremy Fairbank, [HTML5DevConf ES7 and Beyond!](https://speakerdeck.com/jfairbank/html5devconf-es7-and-beyond): ES7 新增语法点介绍 - Timothy Gu, [How to Read the ECMAScript Specification](https://timothygu.me/es-howto/): 如何读懂 ES6 规格 @@ -103,7 +103,7 @@ - Axel Rauschmayer, [Enumerability in ECMAScript 6](http://www.2ality.com/2015/10/enumerability-es6.html) - Axel Rauschmayer, [ES proposal: Object.getOwnPropertyDescriptors()](http://www.2ality.com/2016/02/object-getownpropertydescriptors.html) - TC39, [Object.getOwnPropertyDescriptors Proposal](https://github.com/tc39/proposal-object-getownpropertydescriptors) -- David Titarenco, [How Spread Syntax Breaks Javascript](https://dvt.name/2018/06/02/spread-syntax-breaks-javascript/): 扩展运算符的一些不合理的地方 +- David Titarenco, [How Spread Syntax Breaks JavaScript](https://dvt.name/2018/06/02/spread-syntax-breaks-javascript/): 扩展运算符的一些不合理的地方 ## Symbol @@ -172,7 +172,7 @@ - Kyle Simpson, [ES6 Generators: Complete Series](http://davidwalsh.name/es6-generators): 由浅入深探讨 Generator 的系列文章,共四篇 - Gajus Kuizinas, [The Definitive Guide to the JavaScript Generators](http://gajus.com/blog/2/the-definetive-guide-to-the-javascript-generators): 对 Generator 的综合介绍 - Jan Krems, [Generators Are Like Arrays](https://gist.github.com/jkrems/04a2b34fb9893e4c2b5c): 讨论 Generator 可以被当作数据结构看待 -- Harold Cooper, [Coroutine Event Loops in Javascript](http://syzygy.st/javascript-coroutines/): Generator 用于实现状态机 +- Harold Cooper, [Coroutine Event Loops in JavaScript](http://syzygy.st/javascript-coroutines/): Generator 用于实现状态机 - Ruslan Ismagilov, [learn-generators](https://github.com/isRuslan/learn-generators): 编程练习,共 6 道题 - Steven Sanderson, [Experiments with Koa and JavaScript Generators](http://blog.stevensanderson.com/2013/12/21/experiments-with-koa-and-javascript-generators/): Generator 入门介绍,以 Koa 框架为例 - Mahdi Dibaiee, [ES7 Array and Generator comprehensions](http://dibaiee.ir/es7-array-generator-comprehensions/):ES7 的 Generator 推导 @@ -189,7 +189,7 @@ - Daniel Brain, [Understand promises before you start using async/await](https://medium.com/@bluepnume/learn-about-promises-before-you-start-using-async-await-eb148164a9c8): 讨论 async/await 与 Promise 的关系 - Jake Archibald, [Async functions - making promises friendly](https://developers.google.com/web/fundamentals/getting-started/primers/async-functions) - Axel Rauschmayer, [ES proposal: asynchronous iteration](http://www.2ality.com/2016/10/asynchronous-iteration.html): 异步遍历器的详细介绍 -- Dima Grossman, [How to write async await without try-catch blocks in Javascript](http://blog.grossman.io/how-to-write-async-await-without-try-catch-blocks-in-javascript/): 除了 try/catch 以外的 async 函数内部捕捉错误的方法 +- Dima Grossman, [How to write async await without try-catch blocks in JavaScript](http://blog.grossman.io/how-to-write-async-await-without-try-catch-blocks-in-javascript/): 除了 try/catch 以外的 async 函数内部捕捉错误的方法 - Mostafa Gaafa, [6 Reasons Why JavaScript’s Async/Await Blows Promises Away](https://hackernoon.com/6-reasons-why-javascripts-async-await-blows-promises-away-tutorial-c7ec10518dd9): Async 函数的6个好处 - Mathias Bynens, [Asynchronous stack traces: why await beats Promise#then()](https://mathiasbynens.be/notes/async-stack-traces): async 函数可以保留错误堆栈 @@ -253,7 +253,7 @@ - Stoyan Stefanov, [Writing ES6 today with jstransform](http://www.phpied.com/writing-es6-today-with-jstransform/) - ES6 Module Loader, [ES6 Module Loader Polyfill](https://github.com/ModuleLoader/es6-module-loader): 在浏览器和 node.js 加载 ES6 模块的一个库,文档里对 ES6 模块有详细解释 - Paul Miller, [es6-shim](https://github.com/paulmillr/es6-shim): 一个针对老式浏览器,模拟 ES6 部分功能的垫片库(shim) -- army8735, [Javascript Downcast](https://github.com/army8735/jsdc): 国产的 ES6 到 ES5 的转码器 +- army8735, [JavaScript Downcast](https://github.com/army8735/jsdc): 国产的 ES6 到 ES5 的转码器 - esnext, [ES6 Module Transpiler](https://github.com/esnext/es6-module-transpiler):基于 node.js 的将 ES6 模块转为 ES5 代码的命令行工具 - Sebastian McKenzie, [BabelJS](http://babeljs.io/): ES6 转译器 - SystemJS, [SystemJS](https://github.com/systemjs/systemjs): 在浏览器中加载 AMD、CJS、ES6 模块的一个垫片库 diff --git a/docs/regex.md b/docs/regex.md index 0a120c3..9fa854f 100644 --- a/docs/regex.md +++ b/docs/regex.md @@ -307,7 +307,7 @@ ES6 为正则表达式新增了`flags`属性,会返回正则表达式的修饰 正则表达式中,点(`.`)是一个特殊字符,代表任意的单个字符,但是有两个例外。一个是四个字节的 UTF-16 字符,这个可以用`u`修饰符解决;另一个是行终止符(line terminator character)。 -所谓行终止符,就是该字符表示一行的终结。以下四个字符属于”行终止符“。 +所谓行终止符,就是该字符表示一行的终结。以下四个字符属于“行终止符”。 - U+000A 换行符(`\n`) - U+000D 回车符(`\r`) @@ -352,14 +352,14 @@ re.flags // 's' JavaScript 语言的正则表达式,只支持先行断言(lookahead)和先行否定断言(negative lookahead),不支持后行断言(lookbehind)和后行否定断言(negative lookbehind)。ES2018 引入[后行断言](https://github.com/tc39/proposal-regexp-lookbehind),V8 引擎 4.9 版(Chrome 62)已经支持。 -“先行断言”指的是,`x`只有在`y`前面才匹配,必须写成`/x(?=y)/`。比如,只匹配百分号之前的数字,要写成`/\d+(?=%)/`。”先行否定断言“指的是,`x`只有不在`y`前面才匹配,必须写成`/x(?!y)/`。比如,只匹配不在百分号之前的数字,要写成`/\d+(?!%)/`。 +“先行断言”指的是,`x`只有在`y`前面才匹配,必须写成`/x(?=y)/`。比如,只匹配百分号之前的数字,要写成`/\d+(?=%)/`。“先行否定断言”指的是,`x`只有不在`y`前面才匹配,必须写成`/x(?!y)/`。比如,只匹配不在百分号之前的数字,要写成`/\d+(?!%)/`。 ```javascript /\d+(?=%)/.exec('100% of US presidents have been male') // ["100"] /\d+(?!%)/.exec('that’s all 44 of them') // ["44"] ``` -上面两个字符串,如果互换正则表达式,就不会得到相同结果。另外,还可以看到,”先行断言“括号之中的部分(`(?=%)`),是不计入返回结果的。 +上面两个字符串,如果互换正则表达式,就不会得到相同结果。另外,还可以看到,“先行断言”括号之中的部分(`(?=%)`),是不计入返回结果的。 “后行断言”正好与“先行断言”相反,`x`只有在`y`后面才匹配,必须写成`/(?<=y)x/`。比如,只匹配美元符号之后的数字,要写成`/(?<=\$)\d+/`。“后行否定断言”则与“先行否定断言”相反,`x`只有不在`y`后面才匹配,必须写成`/(? 1. Return the result of performing Strict Equality Comparison `x === y`. > 1. If `x` is `null` and `y` is `undefined`, return `true`. > 1. If `x` is `undefined` and `y` is `null`, return `true`. -> 1. If `Type(x)` is Number and `Type(y)` is String, +> 1. If `Type(x)` is Number and `Type(y)` is String, > return the result of the comparison `x == ToNumber(y)`. -> 1. If `Type(x)` is String and `Type(y)` is Number, +> 1. If `Type(x)` is String and `Type(y)` is Number, > return the result of the comparison `ToNumber(x) == y`. > 1. If `Type(x)` is Boolean, return the result of the comparison `ToNumber(x) == y`. > 1. If `Type(y)` is Boolean, return the result of the comparison `x == ToNumber(y)`. -> 1. If `Type(x)` is either String, Number, or Symbol and `Type(y)` is Object, then +> 1. If `Type(x)` is either String, Number, or Symbol and `Type(y)` is Object, then > return the result of the comparison `x == ToPrimitive(y)`. -> 1. If `Type(x)` is Object and `Type(y)` is either String, Number, or Symbol, then +> 1. If `Type(x)` is Object and `Type(y)` is either String, Number, or Symbol, then > return the result of the comparison `ToPrimitive(x) == y`. > 1. Return `false`. diff --git a/docs/string.md b/docs/string.md index 9bf46c4..2254018 100644 --- a/docs/string.md +++ b/docs/string.md @@ -803,7 +803,7 @@ jsx` ` ``` -上面的代码通过`jsx`函数,将一个 DOM 字符串转为 React 对象。你可以在 Github 找到`jsx`函数的[具体实现](https://gist.github.com/lygaret/a68220defa69174bdec5)。 +上面的代码通过`jsx`函数,将一个 DOM 字符串转为 React 对象。你可以在 GitHub 找到`jsx`函数的[具体实现](https://gist.github.com/lygaret/a68220defa69174bdec5)。 下面则是一个假想的例子,通过`java`函数,在 JavaScript 代码之中运行 Java 代码。 @@ -811,7 +811,7 @@ jsx` java` class HelloWorldApp { public static void main(String[] args) { - System.out.println(“Hello World!”); // Display the string. + System.out.println("Hello World!"); // Display the string. } } `