es5<==>es6

前端之家收集整理的这篇文章主要介绍了es5<==>es6前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ES6 继承例子:

class Child extends Parent {
  constructor(firstName,lastName,age) {
    super(firstName,lastName)
    this.age = age
  }
}

ES5的等价写法:

function Child(firstName,age) {
  Parent.call(this,firstName,lastName)
  this.age = age
}

Child.prototype = Object.create(Parent.prototype)
Child.constructor = Child

猜你在找的程序笔记相关文章