MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / once

Function once

MathBox/mathbox-bundle.js:40726–40744  ·  view source on GitHub ↗

* Creates a function that is restricted to execute `func` once. Repeat calls to * the function will return the value of the first call. The `func` is executed * with the `this` binding of the created function. * * @static * @memberOf _ * @category Functions * @para

(func)

Source from the content-addressed store, hash-verified

40724 * // `initialize` executes `createApplication` once
40725 */
40726 function once(func) {
40727 var ran,
40728 result;
40729
40730 if (!isFunction(func)) {
40731 throw new TypeError;
40732 }
40733 return function() {
40734 if (ran) {
40735 return result;
40736 }
40737 ran = true;
40738 result = func.apply(this, arguments);
40739
40740 // clear the `func` variable so the function may be garbage collected
40741 func = null;
40742 return result;
40743 };
40744 }
40745
40746 /**
40747 * Creates a function that, when called, invokes `func` with any additional

Callers

nothing calls this directly

Calls 1

isFunctionFunction · 0.70

Tested by

no test coverage detected