最简单的继承和多重继承

A继承B和C,但是B和C没有改变

function C(c) {
  this.c = c
}
C.prototype= {
  fnc() {console.log(this.c)}
}

function B(b) {
  this.b = b
}
B.prototype= {
  fnb() {console.log(this.b)}
}

function A(a, b, c) {
  B.call(this, b)
  C.call(this, c)
  this.a = a
}
A.prototype = {
  fna(){console.log(this.a)}
}
Object.assign(A.prototype, B.prototype, C.prototype)

const a = new A(1, 2, 3)
console.log(a)

const b = new B(2)
console.log(b)

const c = new C(3)
console.log(c)

你可能感兴趣的:(javascript)