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

bind-deep

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bind-deep

Lightweight module for binding a function or object deeply.

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
95
increased by75.93%
Maintainers
1
Weekly downloads
 
Created
Source

bind-deep

npm version Travis license

Description

Bind an object to this in all methods in a function or object. Simple, dependency-free alternative to deep-bind.

Features

  • Works with functions, arrays, and other objects
    • Works with most custom classes, array-like objects, etc.
  • Binds root function and all own, enumerable property functions
    • Includes binding accessors — getters and setters
  • Copies objects and enumerable properties deeply
  • Preserves and copies prototype for all types

Installation

From npm
$ npm install bind-deep
As a dependency
# Create package.json for your own module if you haven't already
$ npm init

# Install bind-deep and add to dependencies
$ npm install bind-deep --save
From source
$ git clone https://github.com/evelynhathaway/bind-deep
$ cd bind-deep/
$ npm install

API

bindDeep(object [Function, Object, Array], thisArg [Object], ...args)
// => bound [Function, Object, Array]

Example

// Require bind-deep
const bindDeep = require("bind-deep");


// Original object and function
// Could also be an actual object
const func = function() {
    // Use `this`
};
func.method = function() {
    // Use `this` again
};

const obj = {
    method() {
        // Use `this`
    }
};


// Deeply bound object and function
// `thisArg` will be what every function and method will see as `this`
const boundObj = bindDeep(obj, thisArg);
// => {method: [Function: bound]}

const boundFunc = bindDeep(func, thisArg);
// => {[Function: bound] method: [Function: bound]}

License

Copyright Evelyn Hathaway, MIT License

Keywords

FAQs

Package last updated on 31 Oct 2018

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