面向对象基础语法

  1. class User{
  2. constructor(name, password){
  3. this.name = name
  4. this.password = password
  5. }
  6. showName(){
  7. console.log(this.name)
  8. }
  9. }
  10. //继承
  11. class Vip extends User{
  12. constructor(name, password, level){
  13. super(name, password)
  14. this.level = level
  15. }
  16. showLevel(){
  17. console.log(this.level)
  18. }
  19. }
  20. let v = new Vip('张三', '21222', 9)
  21. v.showName() // 张三
  22. v.showLevel() // 9