15 lines
316 B
JavaScript
15 lines
316 B
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
exports = module.exports = once;
|
||
|
|
|
||
|
|
// https://github.com/isaacs/once/blob/main/LICENSE (ISC)
|
||
|
|
function once (fn) {
|
||
|
|
const f = function () {
|
||
|
|
if (f.called) return f.value;
|
||
|
|
f.called = true;
|
||
|
|
return f.value = fn.apply(this, arguments);
|
||
|
|
};
|
||
|
|
f.called = false;
|
||
|
|
return f;
|
||
|
|
}
|