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
decreased by-0.22%
Maintainers
2
Install size
30.7 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

Changelog

Source

v1.1.2 - 2023-10-12

Merged

  • Point to the correct file #16

Commits

  • [Tests] migrate tests to Github Actions 4f8b57c
  • [Tests] remove jscs 90eb2ed
  • [meta] update .gitignore 53fcdc3
  • [Tests] up to node v11.10, v10.15, v9.11, v8.15, v6.16, v4.9; use nvm install-latest-npm; run audit script in tests 1fe8f6e
  • [meta] add auto-changelog 1921fcb
  • [Robustness] remove runtime dependency on all builtins except .apply f743e61
  • Docs: enable badges; update wording 503cb12
  • [readme] update badges 290c5db
  • [Tests] switch to nyc for coverage ea360ba
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape cae5e9e
  • [meta] add funding field; create FUNDING.yml c9f4274
  • [Tests] fix eslint errors from #15 f69aaa2
  • [actions] fix permissions 99a0cd9
  • [meta] use npmignore to autogenerate an npmignore file f03b524
  • [Dev Deps] update @ljharb/eslint‑config, eslinttape 7af9300
  • [Dev Deps] update eslint, @ljharb/eslint-config, covert, tape 64a9127
  • [Tests] use aud instead of npm audit e75069c
  • [Dev Deps] update @ljharb/eslint-config, aud, tape d03555c
  • [meta] add safe-publish-latest 9c8f809
  • [Dev Deps] update @ljharb/eslint-config, tape baf6893
  • [meta] create SECURITY.md 4db1779
  • [Tests] add npm run audit c8b38ec
  • Revert "Point to the correct file" 05cdf0f

Readme

Source

function-bind Version Badge

github actions

dependency status dev dependency status License Downloads

npm badge

Implementation of function.prototype.bind

Old versions of phantomjs, Internet Explorer < 9, and node < 0.6 don't support Function.prototype.bind.

Example

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

Installation

npm install function-bind

Contributors

  • Raynos

MIT Licenced

Keywords

FAQs

Last updated on 12 Oct 2023

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