# class-extend

> Backbone like Class.extend utility for Node

Latest version **1.0.0** (published 2025-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install class-extend
pnpm add class-extend
yarn add class-extend
bun add class-extend
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2025-01-10 |
| First published | 2013-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 88 |
| Author | Simon Boudrias |
| Maintainers | sboudrias |
| Keywords | inheritance, oop, class, extend |

## Links

- npm: https://www.npmjs.com/package/class-extend
- Repository: https://github.com/SBoudrias/class-extend
- Homepage: https://github.com/SBoudrias/class-extend#readme
- Issues: https://github.com/SBoudrias/class-extend/issues
- npm.io page: https://npm.io/package/class-extend

## Recent versions

- 1.0.0 (latest) — 2025-01-10
- 0.1.2 — 2015-10-12
- 0.1.1 — 2013-12-31
- 0.1.0 — 2013-12-27

## README

Class.extend
============

Backbone like `.extend` inheritance helper for Node.js

Usage
------------

You basically got two options:

``` javascript
// 1. Extend from the blank class
const Base = require('class-extend');
const Sub = Base.extend();

// 2. Add the .extend helper to a class
MyClass.extend = require('class-extend').extend;
```

#### `.extend()`

`.extend` allow you to assign prototype and static methods.

If no `constructor` method is assigned, the parent constructor method will be called by default.

``` javascript
// Extend a class
const Sub = Parent.extend({
  // Overwrite the default constructor
  constructor() {},

  // Sub class prototypes methods
  hello() { console.log('hello'); }
}, {
  // Constructor static methods
  hey() { console.log('hey'); }
});

Sub.hey();
// LOG: hey

const instance = new Sub();
instance.hello();
// LOG: hello
```

#### `.__super__`

Sub classes are assigned a `__super__` static property pointing to their parent prototype.

``` javascript
const Sub = Parent.extend();
assert(Sub.__super__ === Parent.prototype);
```

License
---------------

Copyright (c) 2025 Simon Boudrias  
Licensed under the MIT license.

---
_Source: https://npm.io/package/class-extend · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
