1. 程式人生 > >javaScript 面向對象 觸發夫級構造函數

javaScript 面向對象 觸發夫級構造函數

struct 構造函數 var str con tor code nbsp return

class Person{
    constructor(name,age){  //直接寫屬性
        this.name=name;
        this.age=age;
        console.log(‘a‘);
    }
    showName(){  //直接可以寫方法
        return this.name
    }
    showAge(){
        return this.age
    }

}
class Student extends Person{ 
    
    showJob(){
        
// return this.job } } var xiaohua=new Student();//a var xiaolv=new Student();//a

javaScript 面向對象 觸發夫級構造函數