function Parent(name) {
this.name = name;
}
Parent.prototype.sayHello = function () {
console.log(`I'm ${this.name}!`)
}
function Child(name, age) {
Parent.call(this, name);
this.age = age;
}
Child.prototype = Object.create(Parent.prototype)
Child.prototype.constructor = Child
Child.prototype.sayHello = function () {
console.log(`I'm ${this.name} and ${this.age} years old!`)
}
Child.prototype.sayAge = function () {
console.log(`I'm ${this.age} years old.`)
}
let parent = new Parent("John");
let child = new Child("Jane", 5);
parent.sayHello();
child.sayHello();
To embed this program on your website, copy the following code and paste it into your website's HTML: