# proto-extend

> Extend objects in JavaScript using the prototype chain

Latest version **1.0.0** (published 2015-04-23) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-04-23 |
| First published | 2015-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Doug Patti |
| Maintainers | dpatti |
| Keywords | object, extend, prototype |

## Links

- npm: https://www.npmjs.com/package/proto-extend
- Repository: https://github.com/dpatti/proto-extend
- Issues: https://github.com/dpatti/proto-extend/issues
- npm.io page: https://npm.io/package/proto-extend

## Recent versions

- 1.0.0 (latest) — 2015-04-23
- 0.1.0 — 2015-01-26

## README

# proto-extend

A tiny library that provides a function to create a prototype chain from
multiple objects.

## Usage

```javascript
var extend = require('proto-extend');
var a = { id: 'a', foo: 1 };
var b = { id: 'b', bar: 2 };
var c = { id: 'c', baz: 3 };

var chain = extend(a, b, c);
```

The above returns a new object with a prototype chain of the following:

```
Object.prototype -> a -> b -> c
```

and has the properties:

```javascript
{
  id: 'c',
  foo: 1,
  bar: 2,
  baz: 3
}
```

For more information on how the prototype chain works, see the MDN article
[Inheritance and the prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain).

## API

### `extend(base, extensions...) -> Object`

The main export. Takes a base and any number of extension objects and returns a
new object. If the base is not an object, `null` will be used instead. Each
extension is converted to a property descriptor map and a new object is created.
Extensions that are not an object are ignored.

### `extend.getOwnPropertyDescriptorMap(object) -> Object`

A helper function used internally but exposed for convenience. It uses the
native methods on Object for getting a list of property names and property
descriptors and creates a map. The main purpose is to feed the second argument
of [`Object.create()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create).

### `extend.flatten(object[, base]) -> Object`

A helper function that takes a prototype chain and flattens it into a new single
object. This is useful if you are passing a prototypal-extended object to a
library that intentionally iterates over only "own" keys. If you specify a
`base`, it will stop flattening when it reaches a prototype of that object. By
default, this is `Object.prototype`, though it will always stop if it reaches
the `null` prototype.

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