Socket
Socket
Sign inDemoInstall

function-bind

Package Overview
Dependencies
0
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    function-bind

Implementation of Function.prototype.bind


Version published
Weekly downloads
51M
increased by2.28%
Maintainers
2
Install size
25.4 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

function-bind

Implementation of function.prototype.bind

Example

I mainly do this for unit tests I run on phantomjs. PhantomJS does not have Function.prototype.bind :(

Function.prototype.bind = require("function-bind")

Installation

npm install function-bind

Contributors

  • Raynos

MIT Licenced

Keywords

FAQs

Last updated on 28 Aug 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc