Get started with inheritance-js CDN
CPOL-1.02 licensed
Simple, flexible library for object inheritance: Inheritance.js.
Tags:- class
- classes
- inherit
- inheritjs
- inherit-js
- inherit.js
- inheritance
- inheritancejs
- inheritance-js
- inheritance.js
- object
- objects
- prototype
Stable version
Copied!
How to start using inheritance-js CDN
// Include the inheritance library
const inherit = require("inherit");
// Define the base class
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a sound.`);
}
}
// Define the derived class
class Dog extends inherit(Animal) {
constructor(name, breed) {
super(name);
this.breed = breed;
}
bark() {
console.log(`${this.name} barks.`);
}
}
// Create instances of the classes
const myDog = new Dog("Fido", "Labrador");
// Call methods on the instance
myDog.speak(); // "Fido makes a sound."
myDog.bark(); // "Fido barks."
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!