• 22.ES9


    扩展运算符与rest参数

        <!-- 
            Rest 参数与 spread 扩展运算符在 ES6 中已经引入,不过 ES6 中只针对于数组,
            在 ES9 中为对象提供了像数组一样的 rest 参数和扩展运算符
         -->
         //rest 参数
            function connect({host, port, ...user}){
                console.log(host);
                console.log(port);
                console.log(user);
            }
    
            connect({
                host: '127.0.0.1',
                port: 3306,
                username: 'root',
                password: 'root',
                type: 'master'
            });
    
    
            //对象合并
            const skillOne = {
                q: '天音波'
            }
    
            const skillTwo = {
                w: '金钟罩'
            }
    
            const skillThree = {
                e: '天雷破'
            }
            const skillFour = {
                r: '猛龙摆尾'
            }
    
            const mangseng = {...skillOne, ...skillTwo, ...skillThree, ...skillFour};
    
            console.log(mangseng)
    
            // ...skillOne   =>  q: '天音波', w: '金钟罩'
    
    

    正则扩展-命名捕获分组

            //声明一个字符串
            let str = '<a href="http://www.atguigu.com">Study</a>';
    
            //提取 url 与 『标签文本』
            const reg = /<a href="(.*)">(.*)<\/a>/;
    
            //执行
            const result = reg.exec(str);
    
            console.log(result);
            // console.log(result[1]);
            // console.log(result[2]);
    
            
            let str = '<a href="http://www.atguigu.com">Study</a>';
            //分组命名
            const reg = /<a href="(?<url>.*)">(?<text>.*)<\/a>/;
    
            const result = reg.exec(str);
    
            console.log(result.groups.url);//http://www.atguigu.com
    
            console.log(result.groups.text);//Study
    

    正则扩展-反向断言

            //声明字符串
            let str = 'JS5211314你知道么555啦啦啦';
            //正向断言
            const reg = /\d+(?=啦)/;
            const result = reg.exec(str);
    
            //反向断言
            const reg = /(?<=么)\d+/;
            const result = reg.exec(str);
            console.log(result);
    

    正则扩展-dotAll模式

            //dot  .  元字符  除换行符以外的任意单个字符
            let str = `
            <ul>
                <li>
                    <a>肖生克的救赎</a>
                    <p>上映日期: 1994-09-10</p>
                </li>
                <li>
                    <a>阿甘正传</a>
                    <p>上映日期: 1994-07-06</p>
                </li>
            </ul>`;
            //声明正则
            // const reg = /<li>\s+<a>(.*?)<\/a>\s+<p>(.*?)<\/p>/;
            const reg = /<li>.*?<a>(.*?)<\/a>.*?<p>(.*?)<\/p>/gs;
            //执行匹配
            // const result = reg.exec(str);
            let result;
            let data = [];
            while(result = reg.exec(str)){
                data.push({title: result[1], time: result[2]});
            }
            //输出结果
            console.log(data);
    
    
  • 相关阅读:
    通过输入方式在Android上进行微博OAuth登录
    Android应用集成支付宝接口的简化
    Tomcat启动时报 java.lang.OutOfMemoryError: Java heap space
    Myeclipse中 Exploded location overlaps an existing deployment解决办法
    SVN提交项目时版本冲突解决方案
    Jsp过滤器Filter配置过滤类型汇总
    myeclipse修改jsp文件的名称之后,再也打不开的解决方案
    文件上传之 commons-fileupload(二)
    文件上传之 commons-fileupload(一)
    常见池化技术
  • 原文地址:https://www.cnblogs.com/AaronNotes/p/14378378.html
Copyright © 2020-2023  润新知