before.js 311 B

123456789101112131415
  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;