Registry / component-bind

component-bind

JSON →
library1.0.0jsnpmunverified

The `component-bind` package provides a minimalist utility for binding function `this` contexts and partially applying arguments. Version 1.0.0, released approximately ten years ago, is its sole stable release, indicating an abandoned development status. Unlike the native `Function.prototype.bind`, this utility offers an additional signature that allows binding a method by its string name on a given object, which can be convenient in certain reflection or dynamic scenarios. It functions as a single, exported utility function without any significant external runtime dependencies. While functional, modern JavaScript environments typically favor the native `Function.prototype.bind` method or arrow functions for managing `this` context due to their native performance and ubiquitous availability. The package is part of the broader 'component' ecosystem, which itself is largely superseded by contemporary module systems and build tools. Its release cadence is non-existent, and it should be considered a stable, unmaintained piece of legacy utility code.

npm install component-bind
INSTALL
IMPORT
SIG · COMPONENT-BIND
C
component-bind
javascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

bind
const bind = require('component-bind');
import { bind } from 'component-bind';
Primarily designed for CommonJS; if used with ESM, bundlers often resolve `require` to a default export. Attempting named import will fail.
bind
import bind from 'component-bind';
const { bind } = require('component-bind');
This assumes an ESM-compatible build or a bundler correctly transforming CommonJS default exports. The package itself doesn't explicitly provide an ESM export map, but most tools infer it.
Type 'bind'
/** @type {import('component-bind')} */ const bind = require('component-bind');
The package does not ship with TypeScript type definitions. JSDoc or manual declaration is necessary for type safety. The above uses JSDoc for CommonJS.

Demonstrates the core `bind` functionality, including binding a function to an object's `this` context, currying arguments, and binding a method by its string name.

const bind = require('component-bind'); // A simple object with a name const user = { name: 'Alice' }; // A function that uses 'this.name' function getName() { return this.name; } // Bind the getName function to the user object const getUserName = bind(user, getName); console.log('Bound function result:', getUserName()); // Expected: Alice // Example of currying arguments function greet(greeting, name) { return `${greeting}, ${name}!`; } // Bind with null context (since 'this' isn't used) and curry the greeting const sayHelloTo = bind(null, greet, 'Hello'); console.log('Curried function result (partially applied):', sayHelloTo('Bob')); // Expected: Hello, Bob! // Bind a method by its string name const product = { id: 'P123', getDescription: function(prefix) { return `${prefix}: ${this.id}`; } }; const getProductDescription = bind(product, 'getDescription'); console.log('Bound method by name:', getProductDescription('Item')); // Expected: Item: P123 // Demonstrating full currying const getSpecificProductDescription = bind(product, 'getDescription', 'Product ID'); console.log('Fully curried method:', getSpecificProductDescription()); // Expected: Product ID: P123
Debug
Known issues
gotchaPrefer native `Function.prototype.bind` in modern JavaScript. It offers better performance, is universally available, and integrates more naturally with language features like arrow functions.
fix
Use `myFunction.bind(thisContext, ...args)` or arrow functions `(...args) => myFunction(thisContext, ...args)`.
affects: >=1.0.0
deprecatedThe 'component' ecosystem, to which `component-bind` belongs, is largely considered obsolete and unmaintained. While the package itself is stable due to its simplicity, there will be no future updates or bug fixes.
fix
Consider migrating to native browser/Node.js APIs or widely maintained utility libraries if starting a new project or refactoring.
affects: >=1.0.0
gotchaThis package does not provide TypeScript type definitions. Using it in a TypeScript project will require manually declaring its types or using `any`.
fix
Create a `declarations.d.ts` file with `declare module 'component-bind' { function bind<T>(obj: T | null, fn: Function, ...args: any[]): Function; function bind<T>(obj: T, name: keyof T, ...args: any[]): Function; export = bind; }`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: bind is not a function
Attempting to use a named import (e.g., `import { bind } from 'component-bind';`) when the package exports a single default function.
fix
For CommonJS, use `const bind = require('component-bind');`. For ESM, use `import bind from 'component-bind';`.
TypeError: this.methodName is not a function
When binding by string name (e.g., `bind(obj, 'methodName')`), `methodName` does not exist as a function on the provided `obj`.
fix
Ensure the string `name` argument correctly refers to an existing method on the `obj` parameter.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
4
Resources
component-bind — npm install component-bind · libregistry