{"id":17142930,"url":"https://github.com/js-choi/proposal-method-extraction","last_synced_at":"2025-10-25T07:51:47.073Z","repository":{"id":66615840,"uuid":"391515075","full_name":"js-choi/proposal-method-extraction","owner":"js-choi","description":"Draft specification for method extraction in JavaScript.","archived":false,"fork":false,"pushed_at":"2021-08-01T15:23:15.000Z","size":1791,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-29T14:38:47.282Z","etag":null,"topics":["javascript","proposal","tc39"],"latest_commit_sha":null,"homepage":"https://jschoi.org/21/es-method-extraction/","language":"HTML","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/js-choi.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":"2021-08-01T03:30:27.000Z","updated_at":"2023-03-04T04:05:31.000Z","dependencies_parsed_at":"2023-04-07T19:54:07.014Z","dependency_job_id":null,"html_url":"https://github.com/js-choi/proposal-method-extraction","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-method-extraction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-method-extraction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-method-extraction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-method-extraction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/js-choi","download_url":"https://codeload.github.com/js-choi/proposal-method-extraction/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245240926,"owners_count":20583102,"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":["javascript","proposal","tc39"],"created_at":"2024-10-14T20:33:13.666Z","updated_at":"2025-10-25T07:51:42.055Z","avatar_url":"https://github.com/js-choi.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Method extraction for JavaScript\nECMAScript Stage-0 Proposal. J. S. Choi, 2021.\n\n* **[Formal specification][]**\n* Babel plugin: Not yet\n\n[formal specification]: http://jschoi.org/21/es-method-extraction/\n\n## Why a method-extraction operator\n[`Function.prototype.bind`][bind] is very common in object-oriented JavaScript code.\nIt is a useful method that allows us to extract object methods\ninto **bound functions** that are not dependent on a particular `this` value\nand which may be used in any object environment.\n`bind` serves as an important link between\nobject-oriented and functional APIs in JavaScript.\n\n[bind]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind\n\nWhy then would an operator that does the same thing?\nBecause there is an important difference.\n\n### `Function.prototype.bind` is insecure\nWhen we run our code in an untrusted environment, global objects may be modified.\nIn particular, `Function.prototype.call`…\n\n\u003e JHD: Want to delete Function.prototype.call and things still work\n\n\u003e JHD: Because then I'm not relying on the .call API. It's not super common to be robust against things like this, but that doesnt mean its not a good goal. We need to allow users to harden their code and prevent edge cases like this.\n\n\u003e JHD: Defense model here is that you run code in an environment you trust, but after that anything could happen. I use Function.bind.call to protect against this.\n\n### Method extraction is common but clunky\n???\n\n### No other current TC39 proposal addresses method extraction\nThere is a proposal for an extension-method operator `::`\nthat ostensibly addresses a similar problem.\nHowever, the extension-method proposal does not solve method extraction\nand explicitly calls it out as an orthogonal non-goal.\n\nIn addition, the extension-method proposal is a successor\nto an older proposal for a bind operator `::`.\nThis older proposal did address method extraction, but it is now inactive.\n\n## Description\n(A [formal specification][] is available.)\n\n**Method extraction** `\u0026.` is a **left-associative infix operator**\nthat binds its right-hand side (a method identifier\nor a dynamic method name in `[` `]`)\nto its left-hand side (the method’s original object),\ncreating a **bound function** in the same manner\nas [`Function.prototype.bind`][bind].\n\nFor example, `arr\u0026.slice` would be roughly\nequivalent to `arr.slice.bind(arr)`,\nexcept that its behavior does not change\nif code elsewhere reassigns the global method `Function.prototype.bind`.\n\nLikewise, `obj\u0026.[Symbol.iterator]` would be roughly\nequivalent to `obj[Symbol.iterator].bind(obj)`.\n\nMethod extraction has equal [precedence][] with\nmember expressions, call expressions, `new` expressions with arguments,\nand optional chains.\n\n[precedence]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence\n\n| Left-hand side                  | Example      |\n| ------------------------------- | ------------ |\n| Primary expressions             | `a\u0026.m`       |\n| Member expressions              | `a.b\u0026.m`     |\n| Call expressions                | `a()\u0026.m`     |\n|`new` expressions with arguments | `new F()\u0026.m` |\n| Optional chains                 | `a?.b\u0026.m`    |\n\nSimilarly to the `?.` optional-chaining token,\nthe `\u0026.` token may be padded by whitespace.\nFor example, `a \u0026. m`\\\nis equivalent to `a\u0026.m`,\\\nand `a \u0026. [Symbol.iterator]`\\\nis equivalent to `a\u0026.[Symbol.iterator]`.\n\n## Real-world examples\nOnly minor formatting changes have been made to the status-quo examples.\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eStatus quo\n\u003cth\u003eWith method extraction\n\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```js\n???\n```\nFrom ???.\n\n\u003ctd\u003e\n\n```js\n???\n```\n\n\u003c/table\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-choi%2Fproposal-method-extraction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjs-choi%2Fproposal-method-extraction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-choi%2Fproposal-method-extraction/lists"}