Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
function-bind
Advanced tools
Package description
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.
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
lodash.bind is a method from the Lodash library that provides similar functionality to function-bind. It allows you to bind functions to a context and optionally prepend arguments. Lodash offers a more extensive set of utility functions, whereas function-bind focuses solely on the bind functionality.
underscore.bind is a method from the Underscore.js library that also provides function binding capabilities. Like Lodash, Underscore.js is a utility library that includes a variety of other functions. Function-bind is a standalone package that implements only the bind functionality.
Readme
Implementation of function.prototype.bind
I mainly do this for unit tests I run on phantomjs. PhantomJS does not have Function.prototype.bind :(
Function.prototype.bind = require("function-bind")
npm install function-bind
FAQs
Implementation of Function.prototype.bind
The npm package function-bind receives a total of 43,159,488 weekly downloads. As such, function-bind popularity was classified as popular.
We found that function-bind demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.