• ES6__字符串、数组、对象的扩展


      1 /**
      2  * 字符串的扩展
      3  */
      4 
      5 // 模板字符串  tab上面的反向符号 
      6 // 添加${}
      7 // let flag = true;
      8 // 
      9 // let html = `<ul>
     10 //               <li>
     11 //                 <span>${'首页'}</span>
     12 //                 <span></span>
     13 //                 <span></span>
     14 //                 <span class="${flag ? 'show' : 'hide'}"></span>
     15 //                 <span></span>
     16 //               </li>
     17 //             </ul>`;
     18 //             
     19 // console.log(html);
     20 
     21 
     22 
     23 /**
     24  * 1 repeat   复制功能
     25  * 2 includes()  查找返回布尔值
     26  *startsWith()   判断开头位置 返回布尔值
     27  *endsWith()     判断结尾位置 返回布尔值
     28  */
     29 
     30 // let str1 = 'a';
     31 // 
     32 // let str2 = str1.repeat(3);
     33 // 
     34 // console.log(str2);
     35 
     36 // let str = 'miaov';
     37 // 
     38 // console.log(str.includes('ao'));  // true
     39 // console.log(str.includes('asd'));  // false
     40 // 
     41 // console.log(str.startsWith('m')); // true
     42 // console.log(str.startsWith('o')); // false
     43 // 
     44 // console.log(str.endsWith('ov')); // true
     45 // console.log(str.endsWith('m')); // true
     46 
     47 
     48 
     49 /**
     50  * 数组的扩展
     51  */
     52 
     53 // Array.from()  类数组转换成数组
     54 
     55 // var lis = document.querySelectorAll('li');
     56 // 
     57 // // console.log(Array.isArray(lis));
     58 // 
     59 // var lis2 = Array.from(lis);
     60 // 
     61 // console.log(lis2);
     62 // console.log(Array.isArray(lis2));
     63 
     64 
     65 // Array.of()  创建数组
     66 
     67 // const arr = Array.of(1);
     68 // 
     69 // console.log(arr);
     70 
     71 
     72 // find()   返回符合元素,没有返回undefind
     73 // findIndex() 返回元素下标,没有返回 -1
     74 
     75 // const arr = [1, 2, 3, 4];
     76 // 
     77 // let res = arr.find(function (a){
     78 //   return a < -100;
     79 // });
     80 // 
     81 // console.log(res);
     82 
     83 // let res = arr.findIndex(function (a){
     84 //   return a < -200;
     85 // });
     86 // 
     87 // console.log(res);
     88 
     89 
     90 // fill()  替换数组的内容,可以选择下标位置进行指定的替换
     91 
     92 // const arr = [1, 2, 3, 4];
     93 // 
     94 // arr.fill('abc', 1, 3);
     95 // 
     96 // console.log(arr);
     97 
     98 
     99 
    100 
    101 /**
    102  * 对象的扩展
    103  */
    104 
    105 // 对象的简洁表示法
    106 
    107 let a = 1;
    108 
    109 // const obj = {
    110 //   a: a
    111 // };
    112 
    113 // const obj = {a}
    114 // 
    115 // console.log(obj);
    116 
    117 // const obj = {
    118 //   fn: function (){
    119 //     console.log(1);
    120 //   },
    121 //   fn2(){
    122 //     console.log(2);
    123 //   }
    124 // }
    125 // 
    126 // obj.fn();
    127 // obj.fn2();
    128 
    129 
    130 
    131 
    132 // Object.is()  判断是否一样
    133 
    134 // console.log(Object.is(NaN, NaN));  //ture
    135 // 
    136 // console.log(Object.is(+0, -0));  //false
    137 
    138 
    139 
    140 // Object.assign()  第一个参数目标对象
    141 // 用于对象的合并,将源对象的所有可枚举属性,复制到目标对象。
    142 
    143 let obj1 = {a: 1};
    144 let obj2 = {a: 2, b: 3};
    145 let obj3 = {c: 'abc'};
    146 
    147 Object.assign(obj1, obj2, obj3);
    148 
    149 console.log(obj1);
  • 相关阅读:
    .Net插件编程模型:MEF和MAF[转载]
    并行任务task
    wpf动画概述
    vs在线工具杂烩
    力挺8天入门wpf【转载】
    vs debug 快捷键
    Visual Studio® 2010 Web Deployment Projects站点编译生成bin同时发表插件
    EasyUI选项卡tab页面处理示例
    显示输入框只能输入的内容
    JqueryeasyUI选项卡选择判定更改内部Iframe地址
  • 原文地址:https://www.cnblogs.com/xiaozhishang/p/8759660.html
Copyright © 2020-2023  润新知