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

invoke.js 843B

123456789101112131415161718192021222324252627
  1. define(['./isFunction', './isArray', './_deepGet', './restArguments', './map'], function (isFunction, isArray, _deepGet, restArguments, map) {
  2. // Invoke a method (with arguments) on every item in a collection.
  3. var invoke = restArguments(function(obj, path, args) {
  4. var contextPath, func;
  5. if (isFunction(path)) {
  6. func = path;
  7. } else if (isArray(path)) {
  8. contextPath = path.slice(0, -1);
  9. path = path[path.length - 1];
  10. }
  11. return map(obj, function(context) {
  12. var method = func;
  13. if (!method) {
  14. if (contextPath && contextPath.length) {
  15. context = _deepGet(context, contextPath);
  16. }
  17. if (context == null) return void 0;
  18. method = context[path];
  19. }
  20. return method == null ? method : method.apply(context, args);
  21. });
  22. });
  23. return invoke;
  24. });