MCPcopy Create free account
hub / github.com/ampproject/amphtml / once

Function once

build-system/common/once.js:6–16  ·  view source on GitHub ↗

* @param {() => T} fn * @return {() => T} * @template T

(fn)

Source from the content-addressed store, hash-verified

4 * @template T
5 */
6function once(fn) {
7 let evaluated = false;
8 let value;
9 return () => {
10 if (!evaluated) {
11 evaluated = true;
12 value = fn();
13 }
14 return value;
15 };
16}
17
18module.exports = {
19 once,

Callers 1

index.jsFile · 0.50

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected