面向对象原来写法
  • 类和构造函数一样

  • 属性和方法分开写的

    // 老版本
    function User(name, pass) {
    this.name = name
    this.pass = pass
    } User.prototype.showName = function () {
    console.log(this.name)
    }
    User.prototype.showPass = function () {
    console.log(this.pass)
    } var u1 = new User('able', '1233')
    u1.showName()
    u1.showPass()
    // 老版本继承
    function VipUser(name, pass, level) {
    User.call(this, name, pass)
    this.level = level
    }
    VipUser.prototype = new User()
    VipUser.prototype.constructor = VipUser
    VipUser.prototype.showLevel = function () {
    console.log(this.level)
    } var v1 = new VipUser('blue', '1234', 3)
    v1.showName()
    v1.showLevel()

新版面向对象

  • 有了 class 关键字、构造器

  • class 里面直接加方法

  • 继承,super 超类==父类

    class User {
    constructor(name, pass) {
    this.name = name
    this.pass = pass
    } showName() {
    console.log(this.name)
    }
    showPass() {
    console.log(this.pass)
    }
    } var u1 = new User('able2', '111')
    u1.showName();// able2
    u1.showPass(); // 111
    
    // 新版本继承 
    class VipUser extends User {
    constructor(name, pass, level) {
    super(name, pass)
    this.level = level
    }
    showLevel(){
    console.log(this.level)
    }
    }
    v1 = new VipUser('blue', '123', 3)
    v1.showLevel();// 3

最新文章

  1. c++ 类的静态变量
  2. 编写jquery常用插件的基本格式
  3. 使用Myeclipse创建自定义签名debug keystore
  4. 记录一些容易忘记的属性 -- UIImageView
  5. 中国海洋大学第四届朗讯杯高级组 I Cuckoo for Hashing
  6. Qt5遇到的问题
  7. ViewRootImpl和WindowManagerService笔记
  8. selenium+firefox时每次都要导入数据解决方法解决方法:
  9. ATM取款小项目
  10. webstorm快捷键收集【转发】
  11. PostgreSQL索引描述
  12. C#-----线程安全的ConcurrentQueue<T>队列
  13. java求最大值以及定义方法调用
  14. 一个RTSP/RTP over TCP 的丢包引起的问题
  15. LeetCode(51):N皇后
  16. javascript es6 箭头函数
  17. 求1~n整数中1出现的次数(《剑指offer》面试题43)
  18. 基于boot2docker部署Docker环境
  19. Python进行Android开发步骤
  20. php中ob缓存机制

热门文章

  1. mysql FULL JOIN关键字 语法
  2. sass、less中的scoped属性
  3. BZOJ 2288: 【POJ Challenge】生日礼物 贪心 + 堆 + 链表
  4. matplotlib中中文字体配置
  5. tomcat安全配置参考
  6. java 中创建线程有哪几种方式?
  7. fedora23安装php,mysql
  8. Delphi XE2 之 FireMonkey 入门(21) - 和 FMX 相关的类(表)
  9. debian 配置静态ip
  10. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_07 缓冲流_3_BufferedInputStream_字节缓冲