{"id":14552,"library":"es-class","title":"ES-Class Utility","description":"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.","status":"abandoned","version":"2.1.1","language":"javascript","source_language":"en","source_url":"git://github.com/WebReflection/es-class","tags":["javascript","ES3","ES5","ES6","ES2015","ES7","KISS","Class","inheritance"],"install":[{"cmd":"npm install es-class","lang":"bash","label":"npm"},{"cmd":"yarn add es-class","lang":"bash","label":"yarn"},{"cmd":"pnpm add es-class","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily designed for CommonJS environments in Node.js. Avoid named imports as it typically exports a default function.","wrong":"import { Class } from 'es-class';","symbol":"Class","correct":"const Class = require('es-class');"},{"note":"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.","wrong":"const Class = require('es-class');","symbol":"Class","correct":"// After <script src=\"//cdnjs.cloudflare.com/ajax/libs/es-class/2.1.1/es-class.js\"></script>\n// Class is available globally."},{"note":"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.","wrong":"import { Class } from 'es-class';","symbol":"Class","correct":"import Class from 'es-class';"}],"quickstart":{"code":"const Class = require('es-class');\n\nconst Person = Class({\n  constructor: function(name, age) {\n    this.name = name;\n    this.age = age;\n  },\n  greet: function() {\n    return `Hello, my name is ${this.name} and I am ${this.age} years old.`;\n  }\n});\n\nconst iWorker = {\n  work: function() { throw new Error('Not implemented'); }\n};\n\nconst Engineer = Class({\n  extends: Person,\n  implements: [iWorker],\n  static: {\n    SOFTWARE: 0,\n    CONSTRUCTIONS: 1\n  },\n  constructor: function (name, age, type) {\n    this.super(name, age);\n    this.type = type;\n  },\n  work: function() {\n    return `Engineer ${this.name} is working on type ${this.type}.`;\n  }\n});\n\nconst me = new Engineer(\n  'Mr. Andrea Giammarchi',\n  36,\n  Engineer.SOFTWARE\n);\n\nconsole.log(me instanceof Person); // true\nconsole.log(me.type);              // 0 (Engineer.SOFTWARE)\nconsole.log(me.greet());\nconsole.log(me.work());","lang":"javascript","description":"Demonstrates defining a base `Person` class, an interface `iWorker`, and an `Engineer` class that `extends` `Person` and `implements` `iWorker`, using `static` properties and `super`."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The `es-class` utility was not correctly imported or required into the current scope, or the browser script tag was not loaded.","error":"ReferenceError: Class is not defined"},{"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.","cause":"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.","error":"TypeError: super must be called with 'new'"},{"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.","cause":"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.","error":"Uncaught TypeError: Class(...) is not a constructor"}],"ecosystem":"npm"}