Es6新特性简单练习

十年河东,十年河西,莫欺少年穷

学无止境,精益求精

Es6新特性简单练习

 参考:https://www.cnblogs.com/ruhaoren/p/11575179.html

Es6 提出了部分新特性,诸如,扩展运算符、剩余参数、Let,const,this指向,for in ,for of,set,map,模板字符串,解构赋值等。

今天索性针对这些小技能,做个练习,方便以后查阅。

代码如下:

  onl oad() {
    this.getdata();
  },

  getdata() {
    let that = this;
    //扩展运算符... 展开对象
    let Parm = {
      url: "url",
      method: "get",
      data: {
        pageindex: 1,
        pagesize: 10
      }
    }
    that.KzFun(Parm);
    //扩展运算符... 展开数组
    let Parm2 = [{
      a: 11,
      b: 22,
      c: 33
    }];
    that.KzFun(Parm2);
    //模板字符串 反引号
    let name = '陈卧龙'
    let str = `你好,我的名字是:${name}`;
    console.log(str);
    //扩展运算符 对象合并
    let arty_1 = {
      name: "陈",
      sex: "男"
    };
    let arty_2 = {
      name: "张",
      sex: "女"
    };
    let arty = {
      ...arty_1,
      ...arty_2
    };
    console.log(arty);
    //
    //扩展运算符 数组合并
    let arty_3 = [{
      name: "陈卧龙",
      sex: "男"
    }, {
      name: "莉莉",
      sex: "女"
    }];
    let arty_4 = [{
      name: "陈大六",
      sex: "男"
    }, {
      name: "婷婷",
      sex: "女"
    }];
    let arty5 = [...arty_3, ...arty_4];
    console.log(arty5);
    //Set 去重
    let MySet = new Set();
    MySet.add(1);
    MySet.add(1);
    MySet.add(2);
    MySet.add(1);
    console.log(MySet);
    //解构赋值-数组
    let Jgfz = [{
      name: "小花咪",
      cate: "猫科动物"
    }, {
      name: "小花狗",
      cate: "犬科动物"
    }];
    let [a, b] = Jgfz;
    console.log(a);
    console.log(b);
    //解构赋值-对象
    let dxjgfz = {
      jgname: "小花咪",
      jgcate: "猫科动物"
    };
    let {
      jgname,
      jgcate,
      sex
    } = dxjgfz;
    console.log(jgname);
    console.log(jgcate);
    console.log(sex); //找不到对应关系,为undefined-------------------------------------------------------
    //For OF  For in 遍历数组
    let Fof = ['北京', '上海', '广州'];
    for (let index in Fof) {
      console.log(index) //输出索引
    }
    //   For in 遍历对象   For OF 不可以遍历对象,会报错---------------------------------------------------
    for (let item of Fof) {
      console.log(item) //输出具体的Item值
    }
    let Fin = {
      name: "梨花",
      cate: "猫科动物",
      age: 2,
      sex: "雄性"
    };
    for (let index in Fin) {
      console.log(index) //输出索引
      console.log(Fin[index]) //输出索引
    }
    //Map 键值对结构体  For OF 遍历map
    let Arr2 = new Map();
    Arr2.set("key1", "value1");
    Arr2.set("key2", "value2");
    for (let [name, value] of Arr2) {
      console.log(name) //
      console.log(value) //
    }
    for (let item of Arr2) {
      console.log(item) //item 为数组
    }
    // 常量 Const  一旦赋值  不可修改
    const cns=1;
    //cns=2;//报错----------------------------------------------

    // 其他诸如箭头函数、class构造器,super【调用父类方法】 和 extends【继承父类】,this 指向,Var 和 Let 的区别在于作用域 等不做演示
  },

  KzFun(...Parm) {
    console.log(...Parm)
  }

参考博客:https://www.cnblogs.com/wang--chao/p/14656871.html   和   https://blog.csdn.net/weixin_43641218/article/details/108396556

 @天才卧龙的不博客

上一篇:数字图像处理程序1


下一篇:MySQL模糊查询再也用不着 like+% 了