{"id":10634,"library":"class-extend","title":"Backbone-like Class Extension Utility","description":"The `class-extend` package provides a utility inspired by Backbone.js's `.extend` method, enabling classical inheritance for JavaScript objects, primarily targeting Node.js environments. It allows developers to create child classes that inherit prototype and static methods from a parent, with an optional constructor definition. Designed before native ES6 `class` syntax was widely adopted, it offers a programmatic way to manage inheritance chains, including access to a `__super__` property for parent prototype referencing. The latest version officially published on npm is `0.1.2`, last updated in 2015. Given its age and the prevalence of native ES6 `class extends` syntax, the package is no longer actively maintained and has a very slow release cadence (effectively none since its last update). Its key differentiator was providing a structured inheritance mechanism in a CommonJS context when native alternatives were less accessible or standardized.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/SBoudrias/class-extend","tags":["javascript","inheritance","oop","class","extend"],"install":[{"cmd":"npm install class-extend","lang":"bash","label":"npm"},{"cmd":"yarn add class-extend","lang":"bash","label":"yarn"},{"cmd":"pnpm add class-extend","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. ES module `import` syntax is not supported.","wrong":"import Base from 'class-extend';","symbol":"Base","correct":"const Base = require('class-extend');"},{"note":"To apply the `.extend` helper to an existing class, import the `extend` function directly. This package is CommonJS-only.","wrong":"import { extend } from 'class-extend';","symbol":"extend","correct":"const extend = require('class-extend').extend;"}],"quickstart":{"code":"const Base = require('class-extend');\n\n// 1. Extend from the blank Base class\nconst Animal = Base.extend({\n  constructor(name) {\n    this.name = name;\n  },\n  sayName() {\n    console.log(`My name is ${this.name}.`);\n  },\n  staticMethod() {\n    console.log('This is a static method from Animal.');\n  }\n}, {\n  // Static properties/methods\n  type: 'Mammal'\n});\n\nconst Dog = Animal.extend({\n  constructor(name, breed) {\n    Animal.prototype.constructor.call(this, name); // Call parent constructor\n    this.breed = breed;\n  },\n  bark() {\n    console.log('Woof!');\n  },\n  describe() {\n    console.log(`I am a ${this.breed} named ${this.name}.`);\n  }\n});\n\nconst myDog = new Dog('Buddy', 'Golden Retriever');\nmyDog.sayName();\nmyDog.bark();\nmyDog.describe();\nconsole.log(`Animal type: ${Animal.type}`);\nDog.__super__.staticMethod();","lang":"javascript","description":"Demonstrates extending from the base class and applying the `extend` helper to create an inheritance chain, including constructor calls and static methods."},"warnings":[{"fix":"Ensure `class-extend` is at least `0.1.1` if relying on correct `constructor` property. Review any logic that directly accesses `child.constructor` to ensure it's not inadvertently targeting the parent class in older versions.","message":"Prior to v0.1.1, a bug caused `child.constructor` to incorrectly point to the parent class's constructor. This was fixed in v0.1.1, meaning code relying on the incorrect behavior would break.","severity":"breaking","affected_versions":"<0.1.1"},{"fix":"For new projects, prefer native ES6 `class extends`. For existing projects using `class-extend`, consider a migration strategy to native classes or using a transpiler like Babel to support modern syntax while maintaining legacy structures.","message":"This package implements a pre-ES6 class inheritance pattern using CommonJS `require()`. Modern JavaScript development typically uses native `class extends` syntax and ES Modules for inheritance, which provides better type checking with TypeScript and more idiomatic module loading. Relying on `class-extend` might complicate integration with modern toolchains.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Evaluate the necessity of `class-extend` in your project. Consider refactoring to native ES6 `class extends` or an actively maintained alternative to ensure ongoing support and security.","message":"The `class-extend` package is effectively abandoned, with its last release over 9 years ago (as of 2025). There will be no further updates, bug fixes, or security patches, which poses a risk for long-term project stability and maintenance.","severity":"gotcha","affected_versions":">=0.1.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"This package is CommonJS-only. If your project is an ES module, you must transpile CommonJS modules (e.g., with Webpack or Rollup) or rewrite the import to dynamic `import('class-extend')` (though `class-extend`'s direct usage patterns might still conflict with modern ES module expectations).","cause":"Attempting to use `require('class-extend')` in an ES module context.","error":"TypeError: require is not a function"},{"fix":"Ensure you have `const Base = require('class-extend');` at the top of your file before attempting to use `Base` or its `extend` method.","cause":"Forgetting to assign the result of `require('class-extend')` to a variable, or attempting to use `Base.extend` without first defining `Base`.","error":"ReferenceError: Base is not defined"},{"fix":"Declare the `extend` property on your class interface or use a type assertion: `(MyClass as any).extend = require('class-extend').extend;` for JavaScript or define an interface if migrating to TypeScript.","cause":"When trying to add the `.extend` helper to an existing TypeScript class, TypeScript's type inference does not automatically know about the dynamically added property.","error":"Property 'extend' does not exist on type 'MyClass'."}],"ecosystem":"npm"}