Extensions S1
- Stage: Stage 1
- Status: Active
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
This proposal introduces a :: operator for defining and using extension methods, getters, and setters on objects without polluting the global namespace. It aims to improve code readability by allowing ad-hoc extensions and reuse of built-in prototypes, with a syntax like obj::method() and obj::ext:name.`. The proposal includes experimental implementations and design documents.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
Extensions and :: operator
Proposal status
This is an ECMAScript (JavaScript) proposal in stage 1.
Note: The proposal could be seen as the reshape of the "virtual method" part of old bind operator proposal, see https://github.com/tc39/proposal-bind-operator/issues/56.
Simple examples
Example of ad-hoc extension methods and accessors
roughly equals to:
Example of using constructors or namespace object as extensions
roughly equals to:
Changes of the old bind operator proposal
- keep
obj::foo()syntax for extension methods - repurpose
obj::fooas extension getters and addobj::foo =as extension setters - separate namespace for ad-hoc extension methods and accessors, do not pollute normal binding names
- add
obj::ext:namesyntax - change operator precedence to same as
. - remove
::obj.foo(use cases can be solved by custom extension + library, or other proposals)