{"id":22021570,"url":"https://github.com/lamansky/extend-prototype","last_synced_at":"2026-05-03T13:33:28.963Z","repository":{"id":92611943,"uuid":"80373222","full_name":"lamansky/extend-prototype","owner":"lamansky","description":"A Node.js module that extends one class with methods from another. Supports getters and setters. Can be used as a static method for a mixin.","archived":false,"fork":false,"pushed_at":"2017-11-27T09:25:19.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T16:45:10.080Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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,"governance":null}},"created_at":"2017-01-29T21:17:15.000Z","updated_at":"2017-01-29T22:06:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"3758aefd-1f90-4999-98d2-7567cf03229f","html_url":"https://github.com/lamansky/extend-prototype","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"8dd3c7f55a42a85c6f2cad3d9e015a18098ca595"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fextend-prototype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fextend-prototype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fextend-prototype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fextend-prototype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/extend-prototype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245085073,"owners_count":20558329,"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:57.476Z","updated_at":"2026-05-03T13:33:28.894Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# extend-prototype\n\n* Extends one class with methods from another.\n* Supports getters and setters.\n* Can (optionally) make use of a whitelist.\n* Can easily be added to a class as a static method.\n\nPackaged as a [Node.js](https://nodejs.org/) module.\n\n## Installation\n\n```bash\nnpm install extend-prototype --save\n```\n\nThe module exposes a single function.\n\n## Function Parameters\n\n* `target`: The object/class to extend.\n* `sources`: An object/class (or an array of objects/classes) with methods to add to the target.\n* `methodWhitelist`: An array of the names of methods to add. (If omitted, all methods are added.)\n* `overwrite`: Whether or not to overwrite existing methods in the target.\n\n## Function Signatures\n\nThe function can accept its arguments in a variety of combinations:\n\n```javascript\nextend(target, sources, methodWhitelist, {overwrite})\nextend(target, sources, methodWhitelist)\nextend(target, sources, {overwrite})\nextend(target, sources)\nsource.extend(target, methodWhitelist, {overwrite})\nsource.extend(target, methodWhitelist)\nsource.extend(target, {overwrite})\nsource.extend(target)\n```\n\n## Usage Examples\n\n### Basic Example\n\n```javascript\nconst extend = require('extend-prototype')\nclass A {}\nclass B {\n  test () {}\n  get value () { return 'example' }\n}\nextend(A, B)\nconst a = new A()\na.test()\na.value // 'example'\n```\n\n### Static Method Example\n\nEasily use `extend-prototype` as a static method on your mixin, like so:\n\n```javascript\nclass Mixin {\n  mixinMethod () {}\n}\nMixin.extend = require('extend-prototype')\n\nclass Test {}\nMixin.extend(Test)\n\nconst test = new Test()\ntest.mixinMethod()\n```\n\n### Example with Arguments\n\nThe following example makes use of the `methodWhitelist` and `overwrite` parameters:\n\n```javascript\nconst extend = require('extend-prototype')\nclass A {\n  include () { return 'from A' }\n}\nclass B {\n  include () { return 'from B' }\n  exclude () {}\n}\n\n// Only add the `include` method, and overwrite the existing one.\nextend(A, B, ['include'], {overwrite: true})\n\nconst a = new A()\na.include() // 'from B'\ntypeof a.exclude // 'undefined'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fextend-prototype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fextend-prototype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fextend-prototype/lists"}