From 2be52481a24bc2a015a72699254383633e1b89e0 Mon Sep 17 00:00:00 2001 From: ruanyf Date: Thu, 12 Jan 2017 11:11:22 +0800 Subject: [PATCH] docs(generator): edit Generator --- docs/generator.md | 6 +++--- docs/regex.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/generator.md b/docs/generator.md index dc9a57e..b74fc35 100644 --- a/docs/generator.md +++ b/docs/generator.md @@ -221,7 +221,7 @@ g[Symbol.iterator]() === g ```javascript function* f() { - for(var i=0; true; i++) { + for(var i = 0; true; i++) { var reset = yield i; if(reset) { i = -1; } } @@ -234,9 +234,9 @@ g.next() // { value: 1, done: false } g.next(true) // { value: 0, done: false } ``` -上面代码先定义了一个可以无限运行的Generator函数`f`,如果`next`方法没有参数,每次运行到`yield`语句,变量`reset`的值总是`undefined`。当`next`方法带一个参数`true`时,上一次的变量`reset`就被重置为这个参数(即`true`),因此上一次的`i`会等于-1,下一轮循环就会从-1开始递增。 +上面代码先定义了一个可以无限运行的 Generator 函数`f`,如果`next`方法没有参数,每次运行到`yield`语句,变量`reset`的值总是`undefined`。当`next`方法带一个参数`true`时,变量`reset`就被重置为这个参数(即`true`),因此`i`会等于`-1`,下一轮循环就会从`-1`开始递增。 -这个功能有很重要的语法意义。Generator函数从暂停状态到恢复运行,它的上下文状态(context)是不变的。通过`next`方法的参数,就有办法在Generator函数开始运行之后,继续向函数体内部注入值。也就是说,可以在Generator函数运行的不同阶段,从外部向内部注入不同的值,从而调整函数行为。 +这个功能有很重要的语法意义。Generator 函数从暂停状态到恢复运行,它的上下文状态(context)是不变的。通过`next`方法的参数,就有办法在 Generator 函数开始运行之后,继续向函数体内部注入值。也就是说,可以在 Generator 函数运行的不同阶段,从外部向内部注入不同的值,从而调整函数行为。 再看一个例子。 diff --git a/docs/regex.md b/docs/regex.md index faf21c7..daa29fd 100644 --- a/docs/regex.md +++ b/docs/regex.md @@ -508,7 +508,7 @@ regex.test('ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ') // true [\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}] // 匹配各种文字的所有非字母的字符,等同于Unicode版的\W -[\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}] +[^\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}] // 匹配所有的箭头字符 const regexArrows = /^\p{Block=Arrows}+$/u;