function Shape(color) {
this.color = color
}
Shape.prototype.duplicate = function() {
console.log('duplicate')
}
function Circle(radius, color) {
Shape.call(this, color)
this.radius = radius
}
Circle.prototype = Object.create(Shape.prototype)
Circle.prototype.constructor = Circle
Circle.prototype.draw = function() {
console.log('draw')
}
function Square(size) {
this.size = size
}
Square.prototype = Object.create(Shape.prototype)
Square.prototype.constructor = Square
const s = new Shape()
const c = new Circle(1, 'red')
const sq = new Square(2)
![](https://i-blog.csdnimg.cn/blog_migrate/942616e20df66d70fb7eca0e8fadddf6.png)
function Shape(color) {
this.color = color
}
Shape.prototype.duplicate = function() {
console.log('duplicate')
}
function extend(Child, Parent) {
Child.prototype = Object.create(Parent.prototype)
Child.prototype.constructor = Child
}
function Circle(radius, color) {
Shape.call(this, color)
this.radius = radius
}
extend(Circle, Shape)
Circle.prototype.draw = function() {
console.log('draw')
}
function Square(size) {
this.size = size
}
extend(Square, Shape)
const s = new Shape()
const c = new Circle(1, 'red')
const sq = new Square(2)
![](https://i-blog.csdnimg.cn/blog_migrate/8d14d853cef6acf36a2796ef0f711bb8.png)
function extend(Child, Parent) {
Child.prototype = Object.create(Parent.prototype)
Child.prototype.constructor = Child
}
function Shape(color) {
this.color = color
}
Shape.prototype.duplicate = function() {
console.log('duplicate')
}
function Circle(radius, color) {
Shape.call(this, color)
this.radius = radius
}
extend(Circle, Shape)
Circle.prototype.draw = function() {
console.log('draw')
}
Circle.prototype.duplicate = function() {
console.log('new duplicate')
}
const s = new Shape()
const c = new Circle(1, 'red')
![](https://i-blog.csdnimg.cn/blog_migrate/6d2a9f6eb49105e2f9431c4e51cacd86.png)
function extend(Child, Parent) {
Child.prototype = Object.create(Parent.prototype)
Child.prototype.constructor = Child
}
function Shape(color) {
this.color = color
}
Shape.prototype.duplicate = function() {
console.log('duplicate')
}
function Circle(radius, color) {
Shape.call(this, color)
this.radius = radius
}
extend(Circle, Shape)
Circle.prototype.draw = function() {
console.log('draw')
}
Circle.prototype.duplicate = function() {
// Shape.prototype.duplicate()
Shape.prototype.duplicate.call(this)
console.log('new duplicate')
}
const s = new Shape()
const c = new Circle(1, 'red')
![](https://i-blog.csdnimg.cn/blog_migrate/91b54ede6db14a82374222f3a6bf9b9a.png)