{"id":20311105,"url":"https://github.com/mcmath/define-accessor","last_synced_at":"2026-05-26T23:33:36.666Z","repository":{"id":57211813,"uuid":"61591328","full_name":"mcmath/define-accessor","owner":"mcmath","description":"Define an ES2015 class getter/setter in ES5","archived":false,"fork":false,"pushed_at":"2016-06-21T02:57:20.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-04T17:57:15.456Z","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}},"created_at":"2016-06-21T01:05:22.000Z","updated_at":"2016-06-21T02:47:13.000Z","dependencies_parsed_at":"2022-08-30T15:31:12.335Z","dependency_job_id":null,"html_url":"https://github.com/mcmath/define-accessor","commit_stats":null,"previous_names":["akim-mcmath/define-accessor"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mcmath/define-accessor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-accessor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-accessor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-accessor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-accessor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcmath","download_url":"https://codeload.github.com/mcmath/define-accessor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdefine-accessor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33543973,"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":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"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-14T17:36:11.359Z","updated_at":"2026-05-26T23:33:36.623Z","avatar_url":"https://github.com/mcmath.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Define Accessor\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 Accessor** is a simple utility for defining a getter/setter in\nES5 with the same [property descriptor][descriptor] as an [ES2015 class][class]\naccessor.\n\n## Install\n\nInstall with [npm][npm]:\n\n```sh\nnpm install --save define-accessor\n```\n\n## Usage\n\nIn ES2015, we might do this:\n\n```js\nclass Octopus {\n  constructor(name) {\n    this.name = name;\n  }\n  get nameEqualsTentacles() {\n    return this.name.length === 8;\n  }\n}\n```\n\nIn ES5, we can do this:\n\n```js\nvar defineAccessor = require('define-accessor');\n\nfunction Octopus(name) {\n  this.name = name;\n}\n\ndefineAccessor(Octopus, 'nameEqualsTentacles', function() {\n  return this.name.length === 8;\n});\n```\n\nAnd here is Vladimir:\n\n```js\nnew Octopus('Vladimir').nameEqualsTentacles; // -\u003e true\n```\n\n## API\n\n#### `defineAccessor(constructor, prop, [getter], [setter])`\n\n| Param | Type | Description |\n| :---- | :--- | :---------- |\n| constructor | `function` | The constructor function whose prototype the accessor will be added to |\n| prop | `string` | The property name of the accessor |\n| [getter] | `function` | A [`getter`][getter-link] function (optional) |\n| [setter] | `function` | A [`setter`][setter-link] function (optional) |\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-accessor.svg?style=flat-square\n[license-badge]: https://img.shields.io/npm/l/define-accessor.svg?style=flat-square\n[build-badge]: https://img.shields.io/travis/akim-mcmath/define-accessor/master.svg?style=flat-square\n[coverage-badge]: https://img.shields.io/coveralls/akim-mcmath/define-accessor/master.svg?style=flat-square\u0026service=github\n[dependencies-badge]: https://img.shields.io/gemnasium/akim-mcmath/define-accessor.svg?style=flat-square\n[npm]: https://www.npmjs.com/package/define-accessor\n[license]: LICENSE\n[travis]: https://travis-ci.org/akim-mcmath/define-accessor\n[coveralls]: https://coveralls.io/github/akim-mcmath/define-accessor?branch=master\n[gemnasium]: https://gemnasium.com/akim-mcmath/define-accessor\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[getter-link]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/get\n[setter-link]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/set\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmath%2Fdefine-accessor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcmath%2Fdefine-accessor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmath%2Fdefine-accessor/lists"}