What is call-bound?
The call-bound npm package is a utility that allows you to get a bound function for a method of an object, ensuring that the method is called with the correct 'this' context. This is particularly useful for methods that are often used in a standalone manner, such as array or string methods.
What are call-bound's main functionalities?
Binding a method to its object
This feature allows you to bind a method to its object, ensuring that the method is always called with the correct 'this' context. In this example, Array.prototype.slice is bound to an array, allowing it to be used as a standalone function.
const callBound = require('call-bound');
const arraySlice = callBound('Array.prototype.slice');
const result = arraySlice([1, 2, 3, 4], 1, 3); // [2, 3]
Other packages similar to call-bound
function-bind
The function-bind package provides a polyfill for Function.prototype.bind, which is a native JavaScript method that allows you to create a new function with a specific 'this' value. While call-bound focuses on binding methods to their objects, function-bind is more general-purpose, allowing any function to be bound to a specific context.
lodash
Lodash is a utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It includes a _.bind method that is similar to call-bound in that it allows you to bind a function to a specific context. However, lodash offers a much broader set of utilities beyond just function binding.
call-bound 


Robust call-bound JavaScript intrinsics, using call-bind
and get-intrinsic
.
Getting started
npm install --save call-bound
Usage/Examples
const assert = require('assert');
const callBound = require('call-bound');
const slice = callBound('Array.prototype.slice');
delete Function.prototype.call;
delete Function.prototype.bind;
delete Array.prototype.slice;
assert.deepEqual(slice([1, 2, 3, 4], 1, -1), [2, 3]);
Tests
Clone the repo, npm install
, and run npm test