Registry / web-framework / es-class

es-class

JSON →
library2.1.1jsnpmunverified

es-class is a JavaScript utility designed to provide a class-like structure with features reminiscent of ES6/ES7, such as `extends`, `constructor`, `super`, `with` for mixins, `static` properties, and `implements` for light interface checking. Its primary differentiator was its robust backward compatibility, targeting environments as old as ES3 (Internet Explorer 6, Android 2) while offering a forward-looking syntax during the transition to native ES6 classes. The package's current stable version is 2.1.1. However, development appears to be abandoned, with no new releases or maintenance activities for several years, making it a legacy solution for modern JavaScript development. It aimed to bridge the gap between pre-ES6 JavaScript and the then-upcoming native `class` syntax.

npm install es-class
INSTALL
IMPORT
SIG · ES-CLASS
E
es-class
web-frameworkjavascriptv2.1.1
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.

Class
const Class = require('es-class');
import { Class } from 'es-class';
Primarily designed for CommonJS environments in Node.js. Avoid named imports as it typically exports a default function.
Class
// After <script src="//cdnjs.cloudflare.com/ajax/libs/es-class/2.1.1/es-class.js"></script> // Class is available globally.
const Class = require('es-class');
In browser environments, `es-class` exposes `Class` as a global variable after the script is loaded. Do not use Node.js `require` in the browser.
Class
import Class from 'es-class';
import { Class } from 'es-class';
When used in an ESM context via a bundler, it's typically imported as a default export, assuming the bundler correctly handles CommonJS interoperability. Avoid named imports.

Demonstrates defining a base `Person` class, an interface `iWorker`, and an `Engineer` class that `extends` `Person` and `implements` `iWorker`, using `static` properties and `super`.

const Class = require('es-class'); const Person = Class({ constructor: function(name, age) { this.name = name; this.age = age; }, greet: function() { return `Hello, my name is ${this.name} and I am ${this.age} years old.`; } }); const iWorker = { work: function() { throw new Error('Not implemented'); } }; const Engineer = Class({ extends: Person, implements: [iWorker], static: { SOFTWARE: 0, CONSTRUCTIONS: 1 }, constructor: function (name, age, type) { this.super(name, age); this.type = type; }, work: function() { return `Engineer ${this.name} is working on type ${this.type}.`; } }); const me = new Engineer( 'Mr. Andrea Giammarchi', 36, Engineer.SOFTWARE ); console.log(me instanceof Person); // true console.log(me.type); // 0 (Engineer.SOFTWARE) console.log(me.greet()); console.log(me.work());
Debug
Known issues
breakingThe `es-class` library introduces its own `Class` function and internal concepts like `extends` (as a property) and `super` (as a method). This can lead to significant confusion and potential conflicts when integrated into modern JavaScript codebases that use native ES6 `class` syntax, which has its own keywords and semantics for inheritance and `super` calls.
fix
For new projects, prefer native ES6 `class` syntax. If integrating with existing `es-class` code, be extremely cautious about namespace collisions and semantic differences. Consider refactoring old code to native classes if possible.
affects: >=1.0.0
deprecatedThe `es-class` library is largely superseded by native ES6 `class` syntax, which offers standard, performant, and well-supported object-oriented patterns directly in the language. The library's approach to mimicking class features is no longer necessary or recommended for new development.
fix
Modernize your codebase by migrating away from `es-class` to native JavaScript `class` definitions. This improves maintainability, tooling support, and leverages contemporary language features.
affects: >=1.0.0
gotchaThis project appears to be abandoned, with no updates or maintenance for many years. This means it is unlikely to receive security patches, bug fixes, or compatibility updates for newer JavaScript runtimes or browser versions. Using abandoned dependencies introduces security and stability risks.
fix
Avoid using `es-class` in new projects. For existing projects, plan for migration to native ES6 classes to mitigate risks associated with unmaintained software.
affects: >=1.0.0
gotchaThe `implements` feature in `es-class` provides only 'light checks' (runtime warnings if a method is missing) and does not offer true compile-time type safety or interface enforcement like TypeScript interfaces. This can create a false sense of security regarding type contracts.
fix
If strong type safety and interface enforcement are required, integrate with TypeScript and use its `implements` keyword for class interfaces. Do not rely on `es-class` for robust type checking.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: Class is not defined
The `es-class` utility was not correctly imported or required into the current scope, or the browser script tag was not loaded.
fix
In CommonJS (Node.js), ensure `const Class = require('es-class');` is at the top of your file. In a browser, verify that the `<script>` tag for `es-class.js` is correctly placed and loaded before its usage.
TypeError: super must be called with 'new'
This error can occur if you attempt to call `super()` directly within an `es-class` constructor instead of `this.super()`, or if the context of `this` is lost.
fix
Ensure that within an `es-class` constructor, you invoke the parent constructor via `this.super(arguments)` or `this.super(param1, param2)`. Also, be mindful of `this` context when passing methods around.
Uncaught TypeError: Class(...) is not a constructor
This error typically occurs if `es-class`'s `Class` function is treated like a native ES6 class (e.g., `new Class(...)`) when it's not set up that way, or if the `Class` function itself hasn't been properly invoked to define the class structure.
fix
Ensure you are using `Class({...})` to define a class, then `new MyClass()` to create an instance. The error might also suggest an incorrect import/require that doesn't yield the `Class` function itself.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
es-class — npm install es-class · libregistry