js继承
cococolor
共 183 字
寄生组合式继承:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function Parent() {} Parent.prototype.a = 1
function Child() { Parent.call(this) }
const obj = {} obj.__proto__ = Parent.prototype
child.prototype = Object.assign(obj, child.prototype)
Child.prototype.constructor = Child
|