1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-25 19:22:21 +00:00

Merge pull request #849 from bigbird231/gh-pages

Reflect章节细节补充
This commit is contained in:
Ruan YiFeng 2019-05-08 07:27:00 -07:00 committed by GitHub
commit f0121e8b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -256,7 +256,7 @@ var myObject = {
Reflect.has(myObject, 'foo') // true Reflect.has(myObject, 'foo') // true
``` ```
如果第一个参数不是对象,`Reflect.has``in`运算符都会报错。 如果第一个参数不是对象,`Reflect.has`方法会报错。
### Reflect.deleteProperty(obj, name) ### Reflect.deleteProperty(obj, name)
@ -273,6 +273,7 @@ Reflect.deleteProperty(myObj, 'foo');
``` ```
该方法返回一个布尔值。如果删除成功,或者被删除的属性不存在,返回`true`;删除失败,被删除的属性依然存在,返回`false` 该方法返回一个布尔值。如果删除成功,或者被删除的属性不存在,返回`true`;删除失败,被删除的属性依然存在,返回`false`
如果第一个参数不是对象,`Reflect.deleteProperty`方法会报错。
### Reflect.construct(target, args) ### Reflect.construct(target, args)
@ -290,6 +291,8 @@ const instance = new Greeting('张三');
const instance = Reflect.construct(Greeting, ['张三']); const instance = Reflect.construct(Greeting, ['张三']);
``` ```
如果第一个参数不是函数,`Reflect.construct`方法会报错。
### Reflect.getPrototypeOf(obj) ### Reflect.getPrototypeOf(obj)
`Reflect.getPrototypeOf`方法用于读取对象的`__proto__`属性,对应`Object.getPrototypeOf(obj)` `Reflect.getPrototypeOf`方法用于读取对象的`__proto__`属性,对应`Object.getPrototypeOf(obj)`
@ -508,6 +511,8 @@ Reflect.ownKeys(myObject)
// ['foo', 'bar', Symbol(baz), Symbol(bing)] // ['foo', 'bar', Symbol(baz), Symbol(bing)]
``` ```
如果第一个参数不是对象,`Reflect.ownKeys`方法会报错。
## 实例:使用 Proxy 实现观察者模式 ## 实例:使用 Proxy 实现观察者模式
观察者模式Observer mode指的是函数自动观察数据对象一旦对象有变化函数就会自动执行。 观察者模式Observer mode指的是函数自动观察数据对象一旦对象有变化函数就会自动执行。