{"id":11347,"library":"modelo","title":"Modelo.js Inheritance Utility","description":"Modelo.js is a JavaScript utility providing a robust and performant mechanism for object inheritance, specifically designed to extend Node.js's `util.inherits` with multiple inheritance capabilities. As of version 4.2.3, it allows developers to inherit from multiple base objects seamlessly, addressing a common limitation in standard JavaScript inheritance patterns. A key feature is the `isInstance` method, which is automatically added to instances and serves as a reliable replacement for the native `instanceof` operator when working with multiple inheritance, as `instanceof` is inherently limited to single-prototype chains. The library emphasizes performance, aiming for overhead comparable to `util.inherits` despite its added complexity. While the release cadence isn't explicitly detailed, the version number suggests ongoing maintenance. It differentiates itself by offering a familiar Node.js-style interface while introducing powerful multiple inheritance features, making it suitable for projects requiring flexible object composition.","status":"active","version":"4.2.3","language":"javascript","source_language":"en","source_url":"git://github.com/kevinconway/Modelo.js","tags":["javascript","class","classes","inherit","inherits","inheritance","mixin","mix-in"],"install":[{"cmd":"npm install modelo","lang":"bash","label":"npm"},{"cmd":"yarn add modelo","lang":"bash","label":"yarn"},{"cmd":"pnpm add modelo","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Modelo.js is primarily designed for CommonJS environments in Node.js. Direct ESM import syntax may not be supported without a build step or dynamic import.","wrong":"import { inherits } from 'modelo';","symbol":"inherits","correct":"const { inherits } = require('modelo');"},{"note":"This imports the entire module object, which contains the 'inherits' function and other potential utilities. ESM default imports may not be available.","wrong":"import modelo from 'modelo';","symbol":"modelo (entire module)","correct":"const modelo = require('modelo');"}],"quickstart":{"code":"const modelo = require('modelo');\n\nfunction Base() {\n    // Base object constructor\n}\nBase.prototype.baseMethod = function baseMethod() {\n    console.log('Method from base object.');\n};\n\nfunction Extension() {\n    // Sub-object constructor\n}\nmodelo.inherits(Extension, Base);\n\nconst extInstance = new Extension();\nextInstance.baseMethod(); // Outputs: Method from base object.\n\nfunction MixinOne() {}\nMixinOne.prototype.methodOne = function() { console.log('From MixinOne'); };\nfunction MixinTwo() {}\nMixinTwo.prototype.methodTwo = function() { console.log('From MixinTwo'); };\n\nfunction Combined() {}\nmodelo.inherits(Combined, MixinOne, MixinTwo);\n\nconst instance = new Combined();\ninstance.methodOne(); // Outputs: From MixinOne\ninstance.methodTwo(); // Outputs: From MixinTwo\n\nconsole.log(instance.isInstance(Combined)); // true\nconsole.log(instance.isInstance(MixinOne)); // true\nconsole.log(instance.isInstance(MixinTwo)); // true","lang":"javascript","description":"Demonstrates basic single and multiple inheritance using `modelo.inherits` and shows how to use the `isInstance` method for multi-inherited objects."},"warnings":[{"fix":"Use the `isInstance` method provided on the created instances (e.g., `instance.isInstance(MixinOne)`) instead of `instanceof` to accurately check for inheritance against all base objects in a multiple inheritance scenario.","message":"When using multiple inheritance with Modelo.js, the native JavaScript 'instanceof' operator will not correctly identify all base objects in the inheritance chain. It will only report true for the first prototype listed in the 'inherits' call.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"When performing multiple inheritance, avoid the `super_` attribute. Instead, directly call the desired parent prototype's method using `<Constructor>.prototype.<method>.call(this, ...)` or `<Constructor>.prototype.<method>.apply(this, ...)`.","message":"The `super_` attribute on constructors (e.g., `Combined.super_`), while present for compatibility with `util.inherits`, only references the first prototype when multiple inheritance is used. Relying on it for method calls in multi-inherited classes can lead to incorrect or incomplete behavior.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use the `isInstance` method provided by Modelo.js on the instance itself: `instance.isInstance(MixinTwo)`.","cause":"Attempting to use the native `instanceof` operator to verify inheritance from a base class that is not the first prototype in a multiple inheritance chain.","error":"TypeError: instance is not an instance of MixinTwo"},{"fix":"For multiple inheritance, directly invoke the method on the specific parent prototype: `MixinTwo.prototype.method.call(this, ...)` instead of relying on `super_`.","cause":"Incorrectly attempting to use `this.constructor.super_.prototype.method.call(this)` in a class that inherits from multiple parents, expecting `super_` to resolve to the correct parent in all cases.","error":"TypeError: Cannot read property 'method' of undefined (or similar error when calling super_ method)"}],"ecosystem":"npm"}