最简单的继承和多重继承

61次阅读

共计 372 个字符,预计需要花费 1 分钟才能阅读完成。

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)

正文完
 0