zoukankan      html  css  js  c++  java
  • 24.ES11

    私有属性

            class Person{
                //公有属性
                name;
                //私有属性
                #age;
                #weight;
                //构造方法
                constructor(name, age, weight){
                    this.name = name;
                    this.#age = age;
                    this.#weight = weight;
                }
    
                intro(){
                    console.log(this.name);
                    console.log(this.#age);
                    console.log(this.#weight);
                }
            }
    
            //实例化
            const girl = new Person('晓红', 18, '45kg');
    
            // console.log(girl.name);
            // console.log(girl.#age);//不能获取私有属性
            // console.log(girl.#weight);//不能获取私有属性
    
            girl.intro();//内部可以获取
    
    

    Promise.allSettled

            //声明两个promise对象
            const p1 = new Promise((resolve, reject)=>{
                setTimeout(()=>{
                    resolve('商品数据 - 1');
                },1000)
            });
    
            const p2 = new Promise((resolve, reject)=>{
                setTimeout(()=>{
                    resolve('商品数据 - 2');
                    // reject('出错啦!');
                },1000)
            });
    
            //调用 allsettled 方法
            const result = Promise.allSettled([p1, p2]);
            
            const res = Promise.all([p1, p2]);
    
            console.log(res);
    

    String.prototype.matchAll

            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>.*?<a>(.*?)<\/a>.*?<p>(.*?)<\/p>/sg
    
            //调用方法
            const result = str.matchAll(reg);
    
            // for(let v of result){
            //     console.log(v);
            // }
    
            const arr = [...result];
    
            console.log(arr);
    
    

    可选链操作符

            // ?.
            function main(config){
                // const dbHost = config && config.db && config.db.host;
                const dbHost = config?.db?.host;
    
                console.log(dbHost);
            }
    
            main({
                db: {
                    host:'192.168.1.100',
                    username: 'root'
                },
                cache: {
                    host: '192.168.1.200',
                    username:'admin'
                }
            })
    

    动态 import

    <body>
        <button id="btn">点击</button>
        <script src="./js/app.js" type="module"></script>
    </body>
    
    //hello.js
    export function hello(){
        alert('Hello');
    }
    
    //app.js
    // import * as m1 from "./hello.js";
    //获取元素
    const btn = document.getElementById('btn');
    
    btn.onclick = function(){
        import('./hello.js').then(module => {
            module.hello();
        });
    }
    

    BigInt

            //大整形
            let n = 521n;
            console.log(n, typeof(n));
    
            //函数
            let n = 123;
            console.log(BigInt(n));
            console.log(BigInt(1.2));
    
            //大数值运算
            let max = Number.MAX_SAFE_INTEGER;
            console.log(max);
            console.log(max + 1);
            console.log(max + 2);
    
            console.log(BigInt(max))
            console.log(BigInt(max) + BigInt(1))
            console.log(BigInt(max) + BigInt(2))
    

    globalThis

    console.log(globalThis);
    
  • 相关阅读:
    redis集群报错,(error) MOVED 15495 127.0.0.1:7003
    在云服务器上时候,我关闭了防火墙还是不能连接!
    redis 集群安装 3主3从3台云主机
    ajax完成团队信息异步添加【实际项目】
    众创项目首页推荐需求
    添加删除表格(js完成)【自己实际项目】
    【JPA 级联保存/级联删除】@OneToMany (双向) 一对多【转】
    页面提交 string数组和list对象集合举例
    Form表单如何传递List数组对象到后台的解决办法(转)
    实现同时提交多个form(基础方法) 收集(转)
  • 原文地址:https://www.cnblogs.com/AaronNotes/p/14379351.html
Copyright © 2011-2022 走看看