{"id":20311095,"url":"https://github.com/mcmath/define-method","last_synced_at":"2026-06-07T00:32:22.709Z","repository":{"id":143768687,"uuid":"61586973","full_name":"mcmath/define-method","owner":"mcmath","description":"Define an ES2015 class method in ES5","archived":false,"fork":false,"pushed_at":"2016-06-21T01:01:23.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-15T02:13:08.342Z","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/mcmath.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-20T23:20:00.000Z","updated_at":"2016-06-21T00:52:12.000Z","dependencies_parsed_at":"2023-05-28T06:30:32.907Z","dependency_job_id":null,"html_url":"https://github.com/mcmath/define-method","commit_stats":null,"previous_names":["akim-mcmath/define-method"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mcmath/define-method","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-method","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-method/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-method/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-method/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcmath","download_url":"https://codeload.github.com/mcmath/define-method/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-method/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34005030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-06T02:00:07.033Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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-14T17:36:09.628Z","updated_at":"2026-06-07T00:32:22.692Z","avatar_url":"https://github.com/mcmath.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Define Method\n\n[![Version][version-badge]][npm]\n[![License][license-badge]][license]\n[![Build][build-badge]][travis]\n[![Coverage][coverage-badge]][coveralls]\n[![Dependencies][dependencies-badge]][gemnasium]\n\n**Define Method** is a simple utility for defining an instance method in ES5\nwith the same [property descriptor][descriptor] as an [ES2015 class][class]\nmethod.\n\n## Install\n\nInstall with [npm][npm]:\n\n```sh\nnpm install --save define-method\n```\n\n## Usage\n\nIn ES2015, we might do this:\n\n```js\nclass Fish {\n  constructor(name) {\n    this.name = name;\n  }\n  greet() {\n    console.log(`Hello, my name is ${this.name} the fish.`);\n  }\n}\n```\n\nIn ES5, we can do this:\n\n```js\nvar defineMethod = require('define-method');\n\nfunction Fish(name) {\n  this.name = name;\n}\n\ndefineMethod(Fish, 'greet', function() {\n  console.log('Hello, my name is ' + this.name + ' the fish.');\n});\n```\n\nAnd here is Vladimir:\n\n```js\nnew Fish('Vladimir').greet(); // 'Hello, my name is Vladimir the fish.'\n```\n\n## API\n\n#### `defineMethod(constructor, prop, method)`\n\n| Param | Type | Description |\n| :---- | :--- | :---------- |\n| constructor | `function` | The constructor function whose prototype the method will be added to |\n| prop | `string` | The property name of the method |\n| method | `function` | The method to add |\n\n## License\n\nCopyright \u0026copy; 2016 Akim McMath. Licensed under the [MIT License][license].\n\n[version-badge]: https://img.shields.io/npm/v/define-method.svg?style=flat-square\n[license-badge]: https://img.shields.io/npm/l/define-method.svg?style=flat-square\n[build-badge]: https://img.shields.io/travis/akim-mcmath/define-method/master.svg?style=flat-square\n[coverage-badge]: https://img.shields.io/coveralls/akim-mcmath/define-method/master.svg?style=flat-square\u0026service=github\n[dependencies-badge]: https://img.shields.io/gemnasium/akim-mcmath/define-method.svg?style=flat-square\n[npm]: https://www.npmjs.com/package/define-method\n[license]: LICENSE\n[travis]: https://travis-ci.org/akim-mcmath/define-method\n[coveralls]: https://coveralls.io/github/akim-mcmath/define-method?branch=master\n[gemnasium]: https://gemnasium.com/akim-mcmath/define-method\n[descriptor]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty\n[class]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmath%2Fdefine-method","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcmath%2Fdefine-method","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmath%2Fdefine-method/lists"}