一. Reflect用法

1. 说明

 Reflect对象与Proxy对象一样,也是 ES6 为了操作对象而提供的新 API。

 Reflect对象的方法与Proxy对象的方法一一对应,只要是Proxy对象的方法,就能在Reflect对象上找到对应的方法。

 Reflect 是一个内置的对象,它提供拦截 JavaScript 操作的方法,这些方法与处理器对象的方法相同。Reflect不是一个函数对象,因此它是不可构造的。

2. Reflect.apply()

 

3. Reflect.construct()

 

4.Reflect.define​Property()

 

5. Reflect.delete​Property()

 

6.Reflect.get()

 

7. Reflect.get​OwnProperty​Descriptor()

 

8. Reflect.get​PrototypeOf()

 

9. Reflect.isExtensible()

 

10. Reflect.own​Keys()

 

11. Reflect.prevent​Extensions()

 

12. Reflect.set()

 

13. Reflect.set​PrototypeOf()

 

二. Promise用法

1. 诞生背景

 ajax要依次请求3个文件,在这之前只能通过回调来实现,导致嵌套越来越多,出现回调地狱现象。

ajax('static/a.json', res => {
    console.log(res)
    ajax('static/b.json', res => {
        console.log(res)
        ajax('static/c.json', res => {
            console.log(res)
        })
    })
})

2. 基本语法

 参考:https://www.cnblogs.com/yaopengfei/p/12341264.html

 

3. 常用Api

 

 

4. 练习

 

 

 

 

 

三. Iterator用法

1. 基本语法

  let authors = {
        allAuthors: {
            fiction: [
                'Agatha Christie',
                'J. K. Rowling',
                'Dr. Seuss'
            ],
            scienceFiction: [
                'Neal Stephenson',
                'Arthur Clarke',
                'Isaac Asimov',
                'Robert Heinlein'
            ],
            fantasy: [
                'J. R. R. Tolkien',
                'J. K. Rowling',
                'Terry Pratchett'
            ]
        }
    }
    authors[Symbol.iterator] = function() {
        let allAuthors = this.allAuthors
        let keys = Reflect.ownKeys(allAuthors)
        let values = []
        return {
            next() {
                if (!values.length) {
                    if (keys.length) {
                        values = allAuthors[keys[0]]
                        keys.shift()
                    }
                }
                return {
                    done: !values.length,
                    value: values.shift()
                }
            }
        }
    }
View Code

相关文章:

  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2021-11-20
  • 2022-01-01
  • 2021-11-18
猜你喜欢
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-11-07
  • 2021-03-31
相关资源
相似解决方案