Skip to content

restrictOnce

Subhajit Sahu edited this page Jul 29, 2022 · 2 revisions

Restrict a function to be used only once.

Alternatives: restrict, restrictOnce, restrictBefore, restrictAfter.


function restrictOnce(x)
// x: a function

const xfunction = require('extra-function');


var count = 0;
var fn = xfunction.restrictOnce(x => ++count);
for (var i=0; i<10; ++i)
  fn(i);
count;
// → 1


References

Clone this wiki locally