ECMAScript6

是版本比较新的js技术支持的也比较多

数组解析

 let a=[1,2,3];
        var [a1,a2,a3]=a;//类似于a1=a[0]
        console.debug(a1,a2,a3);

对象解析

let person={name:"杰大大",age:18};
        var {name,age}=person;//类似于name=person.name
        console.debug(name,age)

箭头函数

 var 函数名 = (参数列表) => {函数内容}等价于一下代码

 Person={
            eat(name){
                console.debug(name+"在吃东西")
            },
            eat1:name=>{console.debug(name+"在吃东西1")},
            eat2:({name})=>{console.debug(name+"在吃东西1")},
        }
        man={name:"杰帅"}
        Person.eat("杰大大")
        Person.eat1("杰帅")
        Person.eat2(man)


ajax请求

Promise是异步编程的一种解决方案

 const p = new Promise((resolve, reject) =>{
            // 这里我们用定时任务模拟异步
            setTimeout(() => {
                const num = Math.random();
                // 随机返回成功或失败
                if (num < 0.5) {
                    resolve("成功!num:" + num)
                } else {
                    reject("出错了!num:" + num)
                }
            }, 300)
        })

        const p = new Promise((resolve, reject) =>{
            // 这里我们用定时任务模拟异步
            setTimeout(() => {
                const num = Math.random();
                // 随机返回成功或失败
                if (num < 0.5) {
                    resolve("成功!num:" + num)
                } else {
                    reject("出错了!num:" + num)
                }
            }, 300)
        })

        // 调用promise
        p.then(function (msg) {
            console.log(msg);
        }).catch(function (msg) {
            console.log(msg);
        })
原文地址:https://www.cnblogs.com/xiaoruirui/p/11780466.html