美文网首页
ES6的面向对象

ES6的面向对象

作者: Maiiiiiiiiiiiid | 来源:发表于2019-05-04 09:01 被阅读0次

    ES6面向对象

    [TOC]


    class Person{
        constructor(name,age){
            this.name = name;
            this.age = age;
        }
        showName(){
            console.log(this.name);
        }
        showAge(){
            console.log(this.age);
        }
    }
    
    
    let p = new Person("maid",14);
    p.showName();
    p.showAge();
    

    继承:

    class Worker extends Person{
        constructor(name,age,job){
            super(name,age);
            this.job = job;
        }
        showJob(){
            console.log(this.job);
        }
    }
    
    
    let w = new Worker("maid",14,"小萝莉");
    w.showJob()
    

    相关文章

      网友评论

          本文标题:ES6的面向对象

          本文链接:https://www.haomeiwen.com/subject/evotoqtx.html