proposal-function-once
proposal-function-once copied to clipboard
A TC39 proposal for an Function.prototype.once method in the JavaScript language.
Let’s say we define: ```js function f (x) { return 6; } ``` We have four options with `once`. ## Option 0: Cache and return cached result Cache and return...
Should we go with an “instance” method on the prototype or a “static” function on the constructor? ## Function.prototype.once This has precedent from, e.g., Function.prototype.bind. Examples From [[email protected]][]: ```js export...
Below is the checklist, we can use this issue to discuss any questions that arise during each of these stages. ## Stage 4 - [ ] committee approval - [...
One common technique for using `once` is with the Event pattern, which allows for subscription to an event as a one-time acknowledgement, as opposed to seeing every event. [Node.js has...
If we cache the result of the first call (see #2), then subsequent calls’ arguments might be different and might not match those of the first call. Although this is...
[As I already wrote](https://github.com/js-choi/proposal-function-once/issues/2#issuecomment-1072081514), [`Function.prototype.once` is available in SugarJS](https://sugarjs.com/docs/#/Function/once) (and IIRC in some other libraries). At the current meeting, [it was decided](https://github.com/babel/proposals/issues/81#issuecomment-1080895854) to rename `Array.prototype.groupBy` [because of a similar conflict...
A common dilemma that has been recurring in #2, #3, #4, and #5 is which is more important in design: * First principles? (E.g., “Once-side-effect functions should be idempotent on...
As https://github.com/js-choi/proposal-function-once/issues/2#issuecomment-1081942617 says, the plenary today was slightly in favor of once functions returning undefined every time (and ignoring arguments), so that all function calls remain idempotent. Any sync error...
As the readme, > If subsequent calls somehow occur before the first call finishes executing, then the subsequent calls are synchronously blocked until the first call finishes. It's not clear...