zoukankan      html  css  js  c++  java
  • 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);
    }
    

      

      

     

      

      

  • 相关阅读:
    高德地图SDK大致使用
    AFNetworking 使用
    蓝牙相关
    svn 常用命令
    通过AutoLayout显示三个等宽视图
    适配相关 --AutoLayout ---SizeClass
    常用网页
    UIViewController加载过程
    UIApplication相关
    实现消息转发功能(调用非自己类方法)
  • 原文地址:https://www.cnblogs.com/karila/p/7874036.html
Copyright © 2011-2022 走看看