Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bind-property-descriptor

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bind-property-descriptor

bind a property descriptor (value, getter and setter)

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
500
decreased by-11.35%
Maintainers
3
Weekly downloads
 
Created
Source

bind-property-descriptor Build Status

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

Install

Installation of the npm package:

> npm install --save bind-property-descriptor

Usage

This test data will be used for the examples:

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.

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.

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 you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet

Keywords

FAQs

Package last updated on 17 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc