No Description

before.js 311B

1234567891011121314
  1. // Returns a function that will only be executed up to (but not including) the
  2. // Nth call.
  3. function before(times, func) {
  4. var memo;
  5. return function() {
  6. if (--times > 0) {
  7. memo = func.apply(this, arguments);
  8. }
  9. if (times <= 1) func = null;
  10. return memo;
  11. };
  12. }
  13. module.exports = before;