定义类 属性 方法 执行

'use strict';
//语法塘
class  User{
    //构造函数
    constructor(name,age){
        this.name=name;
        this.age=age;
    }
//静态方法
    static  getClasName(){
        return 'user';
    }
//构造方法
    changeName(name){
        this.name=name;
    }

    changeAge(age){
        this.age=age;
    }

    //属性
    get info(){
        return 'name:'+this.name+';age:'+this.age;
    }
}
//子类: 继承extends
class  Manager extends  User{
    //构造函数
    constructor(name,age,pwd){
        //父对象
        super(name,age);
        //扩展属性
        this.pwd=pwd;
    }
    //扩展方法
    changPwd(pwd){
        this.pwd=pwd;
    }
}

//立即执行类
let aa=new class uu{
    constructor(name){
        this.name=name;
    }
}('zhang');
console.log(aa);
原文地址:https://www.cnblogs.com/wwz-wwz/p/8689956.html