{"id":25825635,"url":"https://github.com/posrix/es6-class-bind-all","last_synced_at":"2025-02-28T14:06:32.051Z","repository":{"id":74147117,"uuid":"98084636","full_name":"posrix/es6-class-bind-all","owner":"posrix","description":"Automaticlly bind 'this' scope of all methods in es6 class","archived":false,"fork":false,"pushed_at":"2018-07-02T07:21:23.000Z","size":7,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-04T03:46:44.651Z","etag":null,"topics":["bind","class","es6","scope","this"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/es6-class-bind-all","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/posrix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-07-23T08:28:18.000Z","updated_at":"2020-10-26T01:24:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"f3881f27-ba90-474f-b338-3e58b1ec627c","html_url":"https://github.com/posrix/es6-class-bind-all","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posrix%2Fes6-class-bind-all","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posrix%2Fes6-class-bind-all/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posrix%2Fes6-class-bind-all/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posrix%2Fes6-class-bind-all/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posrix","download_url":"https://codeload.github.com/posrix/es6-class-bind-all/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241162485,"owners_count":19920410,"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":["bind","class","es6","scope","this"],"created_at":"2025-02-28T14:06:31.353Z","updated_at":"2025-02-28T14:06:32.042Z","avatar_url":"https://github.com/posrix.png","language":"JavaScript","readme":"## Problem\n\nAs you see, too many `.bind()` operations in constructor. Once you have tons of classes\nare called in callback or whatever something change it's scope, it will be horribly troublesome.\n\n```js\nclass Person {\n  constructor() {\n    this.name = 'Steve'\n    this.age = 20\n    this.gender = 'male'\n\n    this.setName = this.setName.bind(this)\n    this.setAge = this.setAge.bind(this)\n    this.setGender = this.setGender.bind(this)\n  }\n  setName(name) {\n    this.name = name\n  }\n  setAge(age) {\n    this.age = age\n  },\n  setGender(gender) {\n    this.gender = gender\n  }\n}\n```\n\n## Easy Way\n\nBind all methods in constructor.\n\n```js\nimport es6ClassBindAll from 'es6-class-bind-all'\n\nclass Person {\n  constructor() {\n    this.name = 'Jack'\n    this.age = 20\n    this.gender = 'male'\n\n    es6ClassBindAll(this)\n  }\n  setName(name) {\n    this.name = name\n  }\n  setAge(age) {\n    this.age = age\n  },\n  setGender(gender) {\n    this.gender = gender\n  }\n}\n```\n\nOr you can bind specified methods in constructor depend on your situation.\n\n```js\nes6ClassBindAll(this, ['setGender'])\n```\n\n## Install\n\n```bash\nyarn add es6-class-bind-all --dev\n```\n\nor npm\n\n```bash\nnpm install es6-class-bind-all --save-dev\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposrix%2Fes6-class-bind-all","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposrix%2Fes6-class-bind-all","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposrix%2Fes6-class-bind-all/lists"}