https://github.com/olical/heir
Helper functions for prototypical inheritance in JavaScript
https://github.com/olical/heir
classes inheritance javascript
Last synced: about 2 months ago
JSON representation
Helper functions for prototypical inheritance in JavaScript
- Host: GitHub
- URL: https://github.com/olical/heir
- Owner: Olical
- License: unlicense
- Created: 2012-08-27T23:11:17.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2018-04-20T13:14:27.000Z (about 7 years ago)
- Last Synced: 2025-04-08T15:48:28.513Z (2 months ago)
- Topics: classes, inheritance, javascript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/heir
- Size: 82 KB
- Stars: 61
- Watchers: 10
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
Awesome Lists containing this project
README
# Heir [](https://www.npmjs.com/package/heir)
Helper functions for prototypical inheritance in JavaScript.
Use the source code and JSDoc comments as documentation, here's a quick example to get you started.
```javascript
const heir = require('heir')// Create the base class.
function Base() {}// Add a method.
Base.prototype.foo = function () {
return 'Base#foo'
}// Create a sub class which inherits from base.
function Sub() {}
heir.inherit(Sub, Base)// Mix in some functionality enhancing objects.
heir.mixin(Sub, events)
heir.mixin(Sub, pooling)// Change the original method.
Sub.prototype.foo = function () {
return [
'Sub#foo',
Sub._super.foo.call(this)
].join(', ')
}// Create an instance of Sub and call it's method.
const s = new Sub()
s.foo() // Returns "Sub#foo, Base#foo"
```## Unlicense
This project is given to you under the [unlicense][], as documented in the `UNLICENSE` file in this directory. Enjoy.
[unlicense]: http://unlicense.org/