You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

bind-methods

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bind-methods

Bind all methods in an object to itself or a specified context

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
209
36.6%
Maintainers
1
Weekly downloads
 
Created
Source

bind-methods

Bind all methods in an object to itself or a specified context

Install

$ npm install bind-methods

Usage

import bindMethods from 'bind-methods';

const unicorn = {
	name: 'Rainbow',
	message() {
		return `${this.name} is awesome!`;
	}
};

const message = unicorn.message;
message();
//=> Error: Cannot read property 'name' of undefined

bindMethods(unicorn);

const message2 = unicorn.message;
message2();
//=> 'Rainbow is awesome!'

API

bindMethods(input, context?)

Bind methods in input to itself or context if specified.

Returns the input object.

input

Type: object

Object with methods to bind.

context

Type: object
Default: The input object

Object to bind the methods to.

  • auto-bind - Automatically bind methods to their class instance

Keywords

bind

FAQs

Package last updated on 19 Apr 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