Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

_optimizeCb.js 825B

1234567891011121314151617181920212223
  1. // Internal function that returns an efficient (for current engines) version
  2. // of the passed-in callback, to be repeatedly applied in other Underscore
  3. // functions.
  4. function optimizeCb(func, context, argCount) {
  5. if (context === void 0) return func;
  6. switch (argCount == null ? 3 : argCount) {
  7. case 1: return function(value) {
  8. return func.call(context, value);
  9. };
  10. // The 2-argument case is omitted because we’re not using it.
  11. case 3: return function(value, index, collection) {
  12. return func.call(context, value, index, collection);
  13. };
  14. case 4: return function(accumulator, value, index, collection) {
  15. return func.call(context, accumulator, value, index, collection);
  16. };
  17. }
  18. return function() {
  19. return func.apply(context, arguments);
  20. };
  21. }
  22. module.exports = optimizeCb;