Registry / serialization / modelo

modelo

JSON →
library0.0.3jsnpmunverified

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.

npm install modelo
INSTALL
IMPORT
SIG · MODELO
M
modelo
serializationjavascriptv0.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inherits
const { inherits } = require('modelo');
import { inherits } from 'modelo';
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.
modelo (entire module)
const modelo = require('modelo');
import modelo from 'modelo';
This imports the entire module object, which contains the 'inherits' function and other potential utilities. ESM default imports may not be available.

Demonstrates basic single and multiple inheritance using `modelo.inherits` and shows how to use the `isInstance` method for multi-inherited objects.

const modelo = require('modelo'); function Base() { // Base object constructor } Base.prototype.baseMethod = function baseMethod() { console.log('Method from base object.'); }; function Extension() { // Sub-object constructor } modelo.inherits(Extension, Base); const extInstance = new Extension(); extInstance.baseMethod(); // Outputs: Method from base object. function MixinOne() {} MixinOne.prototype.methodOne = function() { console.log('From MixinOne'); }; function MixinTwo() {} MixinTwo.prototype.methodTwo = function() { console.log('From MixinTwo'); }; function Combined() {} modelo.inherits(Combined, MixinOne, MixinTwo); const instance = new Combined(); instance.methodOne(); // Outputs: From MixinOne instance.methodTwo(); // Outputs: From MixinTwo console.log(instance.isInstance(Combined)); // true console.log(instance.isInstance(MixinOne)); // true console.log(instance.isInstance(MixinTwo)); // true
Debug
Known issues
gotchaWhen 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.
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.
affects: >=1.0
gotchaThe `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.
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, ...)`.
affects: >=1.0
Errors
Common errors & fixes
TypeError: instance is not an instance of MixinTwo
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.
fix
Use the `isInstance` method provided by Modelo.js on the instance itself: `instance.isInstance(MixinTwo)`.
TypeError: Cannot read property 'method' of undefined (or similar error when calling super_ method)
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.
fix
For multiple inheritance, directly invoke the method on the specific parent prototype: `MixinTwo.prototype.method.call(this, ...)` instead of relying on `super_`.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
3
Amazon
1
Resources
modelo — npm install modelo · libregistry