underscore-es
Version:
javaScript's functional programming helper library for ES6 and beyond.
14 lines (13 loc) • 381 B
JavaScript
// `_before` : (ahem) a function's function
// -----------------------------------------
// Returns a function that will only be executed up to (but not including) the Nth call.
export default function (times, func) {
var memo;
return function () {
if (--times > 0) {
memo = func.apply(this, arguments);
}
if (times <= 1) func = null;
return memo;
};
}