# bind-property-descriptor

> bind a property descriptor (value, getter and setter)

Latest version **2.0.0** (published 2021-11-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install bind-property-descriptor
pnpm add bind-property-descriptor
yarn add bind-property-descriptor
bun add bind-property-descriptor
```

## 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 | 2.0.0 |
| Published | 2021-11-17 |
| First published | 2016-12-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Julien Fontanet |
| Maintainers | julien-f, marsaud, pdonias |
| Keywords | bind, descriptor, object, property |

## Links

- npm: https://www.npmjs.com/package/bind-property-descriptor
- Repository: https://github.com/JsCommunity/bind-property-descriptor
- Issues: https://github.com/JsCommunity/bind-property-descriptor/issues
- npm.io page: https://npm.io/package/bind-property-descriptor

## Recent versions

- 2.0.0 (latest) — 2021-11-17
- 1.0.0 — 2017-05-03
- 0.0.0 — 2016-12-08

## README

# bind-property-descriptor [![Build Status](https://travis-ci.org/JsCommunity/bind-property-descriptor.png?branch=master)](https://travis-ci.org/JsCommunity/bind-property-descriptor)

> Bind a property descriptor (value, getter and setter).

## Install

Installation of the [npm package](https://npmjs.org/package/bind-property-descriptor):

```
> npm install --save bind-property-descriptor
```

## Usage

This test data will be used for the examples:

```js
const emma = {
  firstName: 'Emma',
  lastName: 'Russel',
  get fullName () {
    return `${this.firstName} ${this.lastName}`
  }
}
```

### `bindPropertyDescriptor(descriptor, thisArg) → boundDescriptor`

> Creates a new property descriptor bound to an object.
>
> The value (if a function), getter and/or setter will be called with
> the bound object.

```js
import { bindPropertyDescriptor } from 'bind-property-descriptor'

const obj = {}

const descriptor = Object.getOwnPropertyDescriptor(emma, 'fullName')
const boundDescriptor = bindPropertyDescriptor(descriptor, emma)

Object.defineProperty(obj, 'fullName', boundDescriptor)
obj.fullName
// → Emma Russel
```

### `getBoundPropertyDescriptor(obj, prop, thisArg = obj) → boundDescriptor`

> Because it's a common case to first get the descriptor and then bind
> it, this helper is provided.

```js
import { getBoundPropertyDescriptor } from 'bind-property-descriptor'

const obj = {}

const boundDescriptor = getBoundPropertyDescriptor(emma, 'fullName')

Object.defineProperty(obj, 'fullName', boundDescriptor)
obj.fullName
// → Emma Russel
```

## Contributions

Contributions are *very* welcomed, either on the documentation or on
the code.

You may:

- report any [issue](https://github.com/JsCommunity/bind-property-descriptor/issues)
  you've encountered;
- fork and create a pull request.

## License

ISC © [Julien Fontanet](https://github.com/julien-f)

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