{"id":15700900,"url":"https://github.com/fishrock123/proposal-const-function-arguments","last_synced_at":"2025-05-12T15:19:03.012Z","repository":{"id":143549482,"uuid":"111170431","full_name":"Fishrock123/proposal-const-function-arguments","owner":"Fishrock123","description":"A proposal to introduce constant function argument references.","archived":false,"fork":false,"pushed_at":"2024-02-13T07:39:19.000Z","size":5,"stargazers_count":6,"open_issues_count":3,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-12T15:18:40.154Z","etag":null,"topics":["ecma262","ecmascript","immutability","javascript","js","proposal","tc39"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fishrock123.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":"2017-11-18T02:38:57.000Z","updated_at":"2022-10-22T01:29:16.000Z","dependencies_parsed_at":"2024-10-24T05:25:36.605Z","dependency_job_id":"3c043f24-14e1-4c81-aeff-ed278d6cb348","html_url":"https://github.com/Fishrock123/proposal-const-function-arguments","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/Fishrock123%2Fproposal-const-function-arguments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fishrock123%2Fproposal-const-function-arguments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fishrock123%2Fproposal-const-function-arguments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fishrock123%2Fproposal-const-function-arguments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fishrock123","download_url":"https://codeload.github.com/Fishrock123/proposal-const-function-arguments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253763962,"owners_count":21960484,"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":["ecma262","ecmascript","immutability","javascript","js","proposal","tc39"],"created_at":"2024-10-03T19:55:58.233Z","updated_at":"2025-05-12T15:19:02.976Z","avatar_url":"https://github.com/Fishrock123.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ECMAScript Const Function Arguments\n\nThis proposal introduces constant function argument references, which allows for better enforcement of explicit variable mutability.\n\n## Status\n\n**Stage:** 0  \n**Champion:** tbd\n\n_For more information see the [TC39 proposal process](https://tc39.github.io/process-document/)._\n\n## Authors\n\n* Jeremiah Senkpiel (@fishrock123)\n\n# Proposal\n\nWhen declaring a function or an arrow function, adding `const` before an argument declaration makes the argument reference immutable, in the same manner as if the argument was a variable declared by the `const` variable declaration keyword. Just like `const` variables, the immutability is only by reference for objects, and does not extend deeply.\n\n```\nfunction (const a) {\n  const b\n\n  // a is immutable in the same way b is\n}\n```\n\n```\n(const a) =\u003e {\n  const b\n\n  // a is immutable in the same way b is\n}\n```\n\n## Interaction with default arguments\n\nDefault arguments still function as normal. The immutability happens once the function body begins, and default argument statements are treated as the declaration assignment.\n\n```\nfunction (const a = 'hello') {\n  const b\n\n  // a is immutable in the same way b is\n  // if `a` was not passed to the function, `a` will be 'hello'\n}\n```\n\nAdditionally, the following example:\n\n```\nfunction outer (\n    const a = 'hello',\n    inner = (function inner (a = 'world') {\n      console.log('inner', a)\n    })()\n  ) {\n  console.log('outer', a)\n}\nouter()\n```\n\nActs in the same way as:\n\n```js\nfunction outer () {\n  const a = 'hello'\n  function inner (a) {\n    a = 'world'\n    console.log('inner', a)\n  }\n  inner()\n  console.log('outer', a)\n}\nouter()\n```\n\n## Interaction with the `arguments` object\n\nConstant function argument make the direct argument references immutable. This does not impact the `arguments` object, in strict or sloppy mode, which hold its own references and may be mutated as normal.\n\nIn sloppy mode, assigning to the arguments object will not update a constant function argument.\n\n```\nfn(1)\n\nfunction fn (const a) {\n  // a is 1\n\n  arguments[0] = 2\n  // a is 1\n  // arguments[0] is 2\n}\n```\n\n## \"What about `let` and `var`?\"\n\nThis proposal only touches what is currently missing. Neither `let` or `var` are necessary as that is already the default behavior.\n\nThe proposal has no impact on lexical or function scoping. As arguments are always declared before the function body, the lexical scope is always the function body.\n\n# Open Questions\n\nWould it be possible to use const function arguments in an arrow function that has just one argument and no parentheses?\n\n```\nconst myFunc = const a =\u003e {\n  const b\n\n  // a is immutable in the same way b is\n}\n```\n\n## Potential short-hand options\n\nIs a short-hand version desirable? What could be used that is still clear on its purpose?\n\n# Grammar\n\nTODO\n\n```grammarkdown\n```\n\n# Resources\n\nTODO?\n\n# TODO\n\nThe following is a high-level list of tasks to progress through each stage of the [TC39 proposal process](https://tc39.github.io/process-document/):\n\n### Stage 1 Entrance Criteria\n\n* [ ] Identified a \"[champion][Champion]\" who will advance the addition.  \n* [x] [Prose][Prose] outlining the problem or need and the general shape of a solution.  \n* [ ] Illustrative [examples][Examples] of usage.  \n* [ ] ~High-level API~ _(proposal does not introduce an API)_.  \n\n### Stage 2 Entrance Criteria\n\n* [ ] [Initial specification text][Specification].  \n* [ ] _Optional_. [Transpiler support][Transpiler].  \n\n### Stage 3 Entrance Criteria\n\n* [ ] [Complete specification text][Specification].  \n* [ ] Designated reviewers have [signed off][Stage3ReviewerSignOff] on the current spec text.  \n* [ ] The ECMAScript editor has [signed off][Stage3EditorSignOff] on the current spec text.  \n\n### Stage 4 Entrance Criteria\n\n* [ ] [Test262](https://github.com/tc39/test262) acceptance tests have been written for mainline usage scenarios and [merged][Test262PullRequest].  \n* [ ] Two compatible implementations which pass the acceptance tests: [\\[1\\]][Implementation1], [\\[2\\]][Implementation2].  \n* [ ] A [pull request][Ecma262PullRequest] has been sent to tc39/ecma262 with the integrated spec text.  \n* [ ] The ECMAScript editor has signed off on the [pull request][Ecma262PullRequest].  \n\n# Misc\n\nProposal formatting taken from [rbuckton's proposal-shorthand-improvements](https://github.com/rbuckton/proposal-shorthand-improvements).\n\n\u003c!-- The following are shared links used throughout the README: --\u003e\n\n[Champion]: #status\n[Prose]: #proposal\n[Examples]: #proposal\n[Specification]: #todo\n[Transpiler]: #todo\n[Stage3ReviewerSignOff]: #todo\n[Stage3EditorSignOff]: #todo\n[Test262PullRequest]: #todo\n[Implementation1]: #todo\n[Implementation2]: #todo\n[Ecma262PullRequest]: #todo\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffishrock123%2Fproposal-const-function-arguments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffishrock123%2Fproposal-const-function-arguments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffishrock123%2Fproposal-const-function-arguments/lists"}