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

function-bind

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

function-bind

Implementation of Function.prototype.bind

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22M
decreased by-58.36%
Maintainers
2
Weekly downloads
 
Created

What is function-bind?

The function-bind npm package is a polyfill for Function.prototype.bind, which is a method in JavaScript used to create a new function that, when called, has its 'this' keyword set to the provided value. The bind method can also prepend a fixed set of arguments to the arguments passed to the bound function when it is called.

What are function-bind's main functionalities?

Binding a function to a context

This feature allows you to bind a function to a specific context, so that the 'this' keyword inside the function refers to the provided context object.

var bind = require('function-bind');

function greet() {
  return 'Hello, ' + this.name;
}

var context = { name: 'Alice' };
var boundGreet = bind.call(greet, context);

console.log(boundGreet()); // 'Hello, Alice'

Prepending arguments to the bound function

This feature allows you to create a new function by not only binding it to a context but also prepending arguments to it. When the new function is called, these arguments are passed in front of any other provided arguments.

var bind = require('function-bind');

function add(a, b) {
  return a + b;
}

var addOne = bind.call(add, null, 1);

console.log(addOne(2)); // 3

Other packages similar to function-bind

Keywords

FAQs

Package last updated on 14 Feb 2016

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