{"id":19320261,"url":"https://github.com/jlyonsmith/auto-bind2","last_synced_at":"2026-05-16T00:09:47.045Z","repository":{"id":57187218,"uuid":"101450205","full_name":"jlyonsmith/auto-bind2","owner":"jlyonsmith","description":"A Javascript autoBind() function with a customizable filter and defaults for React","archived":false,"fork":false,"pushed_at":"2018-03-15T23:33:01.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-25T01:12:23.708Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlyonsmith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-25T23:47:08.000Z","updated_at":"2018-04-18T23:52:05.000Z","dependencies_parsed_at":"2022-08-28T13:00:15.867Z","dependency_job_id":null,"html_url":"https://github.com/jlyonsmith/auto-bind2","commit_stats":null,"previous_names":["jamoki/auto-bind2"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jlyonsmith/auto-bind2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlyonsmith%2Fauto-bind2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlyonsmith%2Fauto-bind2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlyonsmith%2Fauto-bind2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlyonsmith%2Fauto-bind2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlyonsmith","download_url":"https://codeload.github.com/jlyonsmith/auto-bind2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlyonsmith%2Fauto-bind2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33085173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T01:28:01.953Z","updated_at":"2026-05-16T00:09:47.021Z","avatar_url":"https://github.com/jlyonsmith.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ES6 Class Auto Binder\n\nA Javascript ES6 class autoBind() function with a customizable filter and defaults for React.\n\n## Why Build This?\n\nThis package exposes an `autoBind` function that calls `bind()` on 'methods' in you ES6 `class` so that `this` always refers to the `class` object instance and not `window` or some other random object.  It avoids the need to call `bind()` multiple times in your constructor, like this:\n\n```Javascript\nclass Foo {\n  constructor() {\n    this.onClick = this.onClick.bind()\n    this.onDrag = this.onDrag.bind()\n    this.onWhatever = this.onWhatever.bind()\n    ...\n  }\n  ...\n}\n```\n\nInstead you just write:\n\n```Javascript\nclass Foo {\n  constructor() {\n    autoBind(this)\n  }\n  ...\n}\n```\n\nThere are a few `autoBind` functions out there already, and they work great.  However what I really felt was needed was a fully customizable function that used a filter callback so that it would work with whatever naming conventions you used for your callback functions.\n\n## Usage\n\nInstall the package with:\n\n```Shell\nnpm install auto-bind2\n```\n\nImport it using:\n\n```Javascript\nimport autoBind from 'auto-bind2'\n// OR\nvar autoBind = require('auto-bind2')\n```\n\nThe function takes a `this` pointer and an optional filter method, e.g.:\n\n```Javascript\nautoBind(this)\n\nautoBind(this, (funcName) =\u003e (funcName.startsWith('on')))\n\nautoBind(this, (funcName) =\u003e (['onClick', 'onDrag', 'onEvent'].includes(funcName)))\n```\n\nThe library includes support for React.  React `Component` methods are already bound, so you can exclude them with:\n\n```Javascript\nimport { reactAutoBind } from 'auto-bind2'\n\nreactAutoBind(this)\n```\n\nor:\n\n```Javascript\nimport { isReactMethod, autoBind } from 'auto-bind2'\n\nautoBind(this, isReactMethod)\n```\n\n## About\n\nThe code is written in ES6 Javascript and built to target NodeJS v8, Chrome v60 and uglification.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlyonsmith%2Fauto-bind2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlyonsmith%2Fauto-bind2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlyonsmith%2Fauto-bind2/lists"}