{"id":10655,"library":"component-bind","title":"Component Bind Utility","description":"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.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/component/bind","tags":["javascript","bind","utility"],"install":[{"cmd":"npm install component-bind","lang":"bash","label":"npm"},{"cmd":"yarn add component-bind","lang":"bash","label":"yarn"},{"cmd":"pnpm add component-bind","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily designed for CommonJS; if used with ESM, bundlers often resolve `require` to a default export. Attempting named import will fail.","wrong":"import { bind } from 'component-bind';","symbol":"bind","correct":"const bind = require('component-bind');"},{"note":"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.","wrong":"const { bind } = require('component-bind');","symbol":"bind","correct":"import bind from 'component-bind';"},{"note":"The package does not ship with TypeScript type definitions. JSDoc or manual declaration is necessary for type safety. The above uses JSDoc for CommonJS.","symbol":"Type 'bind'","correct":"/** @type {import('component-bind')} */\nconst bind = require('component-bind');"}],"quickstart":{"code":"const bind = require('component-bind');\n\n// A simple object with a name\nconst user = { name: 'Alice' };\n\n// A function that uses 'this.name'\nfunction getName() {\n  return this.name;\n}\n\n// Bind the getName function to the user object\nconst getUserName = bind(user, getName);\nconsole.log('Bound function result:', getUserName()); // Expected: Alice\n\n// Example of currying arguments\nfunction greet(greeting, name) {\n  return `${greeting}, ${name}!`;\n}\n\n// Bind with null context (since 'this' isn't used) and curry the greeting\nconst sayHelloTo = bind(null, greet, 'Hello');\nconsole.log('Curried function result (partially applied):', sayHelloTo('Bob')); // Expected: Hello, Bob!\n\n// Bind a method by its string name\nconst product = {\n  id: 'P123',\n  getDescription: function(prefix) {\n    return `${prefix}: ${this.id}`;\n  }\n};\n\nconst getProductDescription = bind(product, 'getDescription');\nconsole.log('Bound method by name:', getProductDescription('Item')); // Expected: Item: P123\n\n// Demonstrating full currying\nconst getSpecificProductDescription = bind(product, 'getDescription', 'Product ID');\nconsole.log('Fully curried method:', getSpecificProductDescription()); // Expected: Product ID: P123","lang":"javascript","description":"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."},"warnings":[{"fix":"Use `myFunction.bind(thisContext, ...args)` or arrow functions `(...args) => myFunction(thisContext, ...args)`.","message":"Prefer native `Function.prototype.bind` in modern JavaScript. It offers better performance, is universally available, and integrates more naturally with language features like arrow functions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider migrating to native browser/Node.js APIs or widely maintained utility libraries if starting a new project or refactoring.","message":"The '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.","severity":"deprecated","affected_versions":">=1.0.0"},{"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; }`.","message":"This package does not provide TypeScript type definitions. Using it in a TypeScript project will require manually declaring its types or using `any`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For CommonJS, use `const bind = require('component-bind');`. For ESM, use `import bind from 'component-bind';`.","cause":"Attempting to use a named import (e.g., `import { bind } from 'component-bind';`) when the package exports a single default function.","error":"TypeError: bind is not a function"},{"fix":"Ensure the string `name` argument correctly refers to an existing method on the `obj` parameter.","cause":"When binding by string name (e.g., `bind(obj, 'methodName')`), `methodName` does not exist as a function on the provided `obj`.","error":"TypeError: this.methodName is not a function"}],"ecosystem":"npm"}