{"id":22021464,"url":"https://github.com/lamansky/efn","last_synced_at":"2026-04-17T00:32:02.108Z","repository":{"id":57220233,"uuid":"120181429","full_name":"lamansky/efn","owner":"lamansky","description":"[Node.js] Extracts a Function. Gets an object method while preserving its binding.","archived":false,"fork":false,"pushed_at":"2019-11-23T17:33:34.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T23:16:35.765Z","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/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-04T12:07:02.000Z","updated_at":"2019-11-23T17:33:36.000Z","dependencies_parsed_at":"2022-08-29T02:12:58.198Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/efn","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fefn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fefn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fefn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fefn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/efn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245084909,"owners_count":20558302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-30T06:12:12.534Z","updated_at":"2026-04-17T00:31:53.042Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Extracted Function (efn)\n\nIf you assign an object method to a variable (or pass it to a function as a callback argument) and then call it later, the method will be called without being bound to the object. In other words, it’ll have no `this` context. To fix this, use this module to “extract” the method from the object.\n\nThis module provides the same functionality as the proposed [unary bind operator](https://github.com/tc39/proposal-bind-operator).\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 4.0.0 or above.\n\n```bash\nnpm i efn\n```\n\n## API\n\nThe module exports a single function.\n\n### Parameters\n\n1. `obj` (object): The object from which you want to extract a method.\n2. `key` (string, number, or symbol): The key that points to the function you’re extracting.\n\n### Return Value\n\nThe extracted function, bound to `obj`.\n\n## Example\n\n```javascript\nclass Test {\n  a () { return this.b() }\n  b () { return 'value' }\n}\n\nconst test = new Test()\n\n// Before:\n\ntest.a() // 'value'\n\nconst callback = test.a\ncallback() // Throws TypeError: Cannot read property 'b' of undefined\n\n// After:\n\nconst efn = require('efn')\n\nconst extracted = efn(test, 'a')\nextracted() // 'value'\n```\n\n## Related\n\nThis module is part of the `fn` family of modules.\n\n* [ffn](https://github.com/lamansky/ffn): Filtering Function\n* [jfn](https://github.com/lamansky/jfn): Joined Function\n* [mfn](https://github.com/lamansky/mfn): Memoized Function\n* [ofn](https://github.com/lamansky/ofn): Overloaded Function\n* [pfn](https://github.com/lamansky/pfn): Possible Function\n* [qfn](https://github.com/lamansky/qfn): Qualified Function\n* [vfn](https://github.com/lamansky/vfn): Variadic Function\n* [wfn](https://github.com/lamansky/wfn): Wrapper Function\n* [xfn](https://github.com/lamansky/xfn): Extended Function\n* [3fn](https://github.com/lamansky/3fn): Three-Way Comparison Function\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fefn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fefn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fefn/lists"}