1. 程式人生 > >ES6學習之面向物件

ES6學習之面向物件

1.寫法

class  User{
	constructor(name,password){//構造器
			this.name = name;
			this.password = password;
	}
	showName(){
			alert(this.name);
	}
	showPass(){
			alert(this.password);
	}
}

let user  = new User('xk','1234567');
user.showName();
user.shoePass();

2.繼承

 class VipUser extends User{
		constructor(name,password,level){
			super(name,password);//執行父類構造器
			this.level = level;
	}
	showLevel(){
		alert(this.level);
	}
}