Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
This is a small script that adds the ability to inherit other functions prototype objects into your own. It makes prototypical inheritance easy and robust.
Due to there not being any documentation yet, you may want to read my JSDoc comments in the source. They will tell you everything you need to know. Here is a quick example to get you going anyway.
// 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',
this._super.foo.call(this)
].join(', ');
};
// Create an instance of Sub and call it's method.
var s = new Sub();
s.foo(); // Returns "Sub#foo, Base#foo"
You can load this script into your browser using a normal script tag or AMD. You can also use node.js' require
if you are running server side.
The inherit
method used to work by cloning and merging multiple prototypes into one. This meant things like instanceof
didn't work and you could get into some weird scenarios caused by multiple inheritance.
The new inherit
uses the built in prototypical inheritance to provide a much cleaner outcome, as shown in this post about prototypical inheritance. The major change is that you can't inherit from multiple classes any more.
If you still need to have multiple things shared between classes to avoid duplication, you can now use the mixin
method to merge objects into your inheritance hierarchies where required.
You can obtain a copy by cloning this repository with git, installing through npm or bower. Heir is called heir
within both package managers.
If you wish to run the tests you will also need to install Jasmine. You can do this through bower like so.
bower install --dev
Tests are performed using Jasmine in the following browsers.
When testing in the more modern browsers, not Internet Explorer basically, I run it through the very early versions, some midrange versions and the very latest ones too. I don't just do the latest version.
Heir will always be tested and working perfectly in all of them before a release. I will not release anything I think is riddled with bugs. However, if you do spot one, please submit it as an issue and I will get right on it.
Copyright (c) 2012-2013 Oliver Caldwell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Helper functions for prototypical inheritance
We found that heir demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.