• es6之类与对象


    一、类的定义

     class Parent{
            constructor(name="mukewang"){
                this.name=name;
            }
        }
    
        let v_parant=new Parent("v");
        console.log("constructor",v_parant);
    

    类的继承

    // extends 用于继承父类

     //继承
    class Parent{
            constructor(name="mukewang"){
                this.name=name;
            }
        }
    
        class Child extends Parent{
    
        }
    
        console.log("extend", new Child());
    
    //继承传递参数
    //super必须放在设置改变参数的前面
    {
        class Parent{
            constructor(name="mukewang"){
                this.name=name;
            }
        }
    
        class Child extends Parent{
             constructor(name="child"){
                 super(name);
                 this.type="child"
             }
        }
    
        console.log("extend", new Child("hello"));
    }
    

      

    get 、set 方法

        //getter,setter
        class Parent{
            constructor(name="mukewang"){
                this.name=name;
            }
            get longName(){
                return "mk"+this.name
            }
            set longName(value){
                this.name=value;
            }
        }
    
        let v=new Parent();
        console.log("getter",v.longName);
        v.longName="hello"
        console.log("getter",v.longName);
    

     静态方法

    //静态方法
        class Parent{
            constructor(name="numewang"){
                this.name=name;
            }
    
            static tell(){
                console.log("tell");
            }
        }
        Parent.tell();
    
    //静态属性
        class Parent{
            constructor(name="numewang"){
                this.name=name;
            }
    
            static tell(){
                console.log("tell");
            }
        }
    
        Parent.type="test";
        console.log("静态属性",Parent.type);
    }
    

      

      

     

      

      

  • 相关阅读:
    MSSQL—列记录合并
    MSSQL—字符串分离(Split函数)
    如何在ASP.NET Core中自定义Azure Storage File Provider
    从零开始实现ASP.NET Core MVC的插件式开发(六)
    对ASP.NET程序员非常有用的85个工具
    vs-code 配置
    idea-plugin
    VirtualBox中CentOS遇到的问题
    监听器
    线程组复杂场景
  • 原文地址:https://www.cnblogs.com/karila/p/7874036.html
Copyright © 2020-2023  润新知