From dcb12a1be99a189fe3f7cc2a5bd0ebc06bad3da9 Mon Sep 17 00:00:00 2001 From: Ruan YiFeng Date: Wed, 25 Jan 2017 09:24:20 +0800 Subject: [PATCH] docs(Symbol): edit Symbol.unscopables --- docs/symbol.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/symbol.md b/docs/symbol.md index 6ac2cbf..8681b4f 100644 --- a/docs/symbol.md +++ b/docs/symbol.md @@ -807,18 +807,19 @@ Array.prototype[Symbol.unscopables] // entries: true, // fill: true, // find: true, -// findIndex: true, +//   findIndex: true, +// includes: true, // keys: true // } Object.keys(Array.prototype[Symbol.unscopables]) -// ['copyWithin', 'entries', 'fill', 'find', 'findIndex', 'keys'] +// ['copyWithin', 'entries', 'fill', 'find', 'findIndex', 'includes', 'keys'] ``` -上面代码说明,数组有6个属性,会被with命令排除。 +上面代码说明,数组有7个属性,会被`with`命令排除。 ```javascript -// 没有unscopables时 +// 没有 unscopables 时 class MyClass { foo() { return 1; } } @@ -829,7 +830,7 @@ with (MyClass.prototype) { foo(); // 1 } -// 有unscopables时 +// 有 unscopables 时 class MyClass { foo() { return 1; } get [Symbol.unscopables]() { @@ -844,3 +845,4 @@ with (MyClass.prototype) { } ``` +上面代码通过指定`Symbol.unscopables`属性,使得`with`语法块不会在当前作用域寻找`foo`属性,即`foo`将指向外层作用域的变量。